#include<bits/stdc++.h>
#define fi first
#define se second
using namespace std;
const int N = 2e6+7;
int n;
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<double>());
sort(b+1,b+1+n,greater<double>());
for(int i=1;i<=n;i++) {
prefixSumA[i] = prefixSumA[i-1] + a[i];
prefixSumB[i] = prefixSumB[i-1] + b[i];
}
int j = 1;
for(int i=1;i<=n;i++) {
while(j < n && prefixSumA[j + 1] <= prefixSumB[i]) j++;
if(prefixSumB[i] < prefixSumA[j]) res = max(res, double(prefixSumB[i] - i - j)); else
{
res = max(res, double(prefixSumA[j] - i - j));
if(j < n) res = max(res, double(prefixSumB[i] - i - j - 1));
}
}
cout<<fixed<<setprecision(4)<<res;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
2 ms |
340 KB |
Output is correct |
13 |
Correct |
2 ms |
340 KB |
Output is correct |
14 |
Correct |
2 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
340 KB |
Output is correct |
16 |
Correct |
2 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
2 ms |
340 KB |
Output is correct |
13 |
Correct |
2 ms |
340 KB |
Output is correct |
14 |
Correct |
2 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
340 KB |
Output is correct |
16 |
Correct |
2 ms |
340 KB |
Output is correct |
17 |
Correct |
125 ms |
3532 KB |
Output is correct |
18 |
Correct |
132 ms |
3468 KB |
Output is correct |
19 |
Correct |
132 ms |
3456 KB |
Output is correct |
20 |
Correct |
131 ms |
3532 KB |
Output is correct |
21 |
Correct |
155 ms |
3544 KB |
Output is correct |
22 |
Correct |
128 ms |
3532 KB |
Output is correct |
23 |
Correct |
129 ms |
3488 KB |
Output is correct |
24 |
Correct |
126 ms |
3532 KB |
Output is correct |
25 |
Correct |
127 ms |
3612 KB |
Output is correct |
26 |
Correct |
149 ms |
3628 KB |
Output is correct |