#include<bits/stdc++.h>
#define fi first
#define se second
using namespace std;
const int N = 2e6+7;
int n;
long double a[N], b[N], prefixSumA[N], prefixSumB[N], res = 0;
int main()
{
cin>>n;
for(int i=1;i<=n;i++) cin>>a[i]>>b[i];
sort(a+1,a+1+n,greater<long double>());
sort(b+1,b+1+n,greater<long double>());
for(int i=1;i<=n;i++) {
prefixSumA[i] = prefixSumA[i-1] + a[i];
prefixSumB[i] = prefixSumB[i-1] + b[i];
}
/* for(int i=1;i<=2*n;i++) {
int l = 0;
int r = i;
while(l <= r) {
int mid = (l+r)/2;
long double va1 = prefixSumA[mid], va11 = prefixSumB[mid];
long double va2 = prefixSumB[i-mid], va22 = prefixSumA[i-mid];
res = max(res, min(va1 - i, va2 - i));
res = max(res, min(va11 - i, va22 - i));
if(va1 - i > va2 - i) l = mid + 1; else r = mid - 1;
}
} */
int j = 1;
for(int i=1;i<=n;i++) {
res = max(res, min(prefixSumA[i], prefixSumB[j]) - (i + j));
while(prefixSumB[j] - (i + j) < prefixSumA[i] - (i+j)) j++;
res = max(res, min(prefixSumA[i], prefixSumB[j]) - (i + j));
}
printf("%.4lf",(double)res);
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
10 ms |
340 KB |
Output is correct |
3 |
Correct |
11 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Incorrect |
10 ms |
384 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
10 ms |
340 KB |
Output is correct |
3 |
Correct |
11 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Incorrect |
10 ms |
384 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
10 ms |
340 KB |
Output is correct |
3 |
Correct |
11 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Incorrect |
10 ms |
384 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |