#include<bits/stdc++.h>
using namespace std;
int n;
vector<long double> A;
vector<long double> B;
int main(){
long double ans = 0;
cin >> n;
A.assign(n+1, 0);
B.assign(n+1, 0);
for(int i = 1; i <= n; i++)cin >> A[i] >> B[i];
sort(A.begin()+1, A.end());
sort(B.begin()+1, B.end());
reverse(A.begin()+1, A.end());
reverse(B.begin()+1, B.end());
for(int i= 1; i <= n; i++){
A[i]+=A[i-1];
B[i]+=B[i-1];
}
for(int i = 2; i <= 2*n; i++){
int l = max(0, i-n), r = min(i, n), mid;
long double tmp = i;
while(r-l > 1){
int mid = (l+r)>>1;
ans = max(ans, min(A[mid], B[i-mid])-tmp);
if(A[mid]-B[i-mid] > 0)r=mid;
else l = mid;
}
ans = max(ans, min(A[l], B[i-l])-tmp);
ans = max(ans, min(A[r], B[i-r])-tmp);
}
cout << fixed << setprecision(4) << ans;
}
Compilation message
sure.cpp: In function 'int main()':
sure.cpp:23:45: warning: unused variable 'mid' [-Wunused-variable]
23 | int l = max(0, i-n), r = min(i, n), mid;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
2 ms |
332 KB |
Output is correct |
13 |
Correct |
2 ms |
332 KB |
Output is correct |
14 |
Correct |
2 ms |
332 KB |
Output is correct |
15 |
Correct |
2 ms |
332 KB |
Output is correct |
16 |
Correct |
2 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
2 ms |
332 KB |
Output is correct |
13 |
Correct |
2 ms |
332 KB |
Output is correct |
14 |
Correct |
2 ms |
332 KB |
Output is correct |
15 |
Correct |
2 ms |
332 KB |
Output is correct |
16 |
Correct |
2 ms |
332 KB |
Output is correct |
17 |
Correct |
166 ms |
4676 KB |
Output is correct |
18 |
Correct |
172 ms |
4804 KB |
Output is correct |
19 |
Correct |
166 ms |
4700 KB |
Output is correct |
20 |
Correct |
167 ms |
4688 KB |
Output is correct |
21 |
Correct |
185 ms |
4944 KB |
Output is correct |
22 |
Correct |
170 ms |
4820 KB |
Output is correct |
23 |
Correct |
167 ms |
4700 KB |
Output is correct |
24 |
Correct |
164 ms |
4688 KB |
Output is correct |
25 |
Correct |
168 ms |
4684 KB |
Output is correct |
26 |
Correct |
185 ms |
4932 KB |
Output is correct |