#include <bits/stdc++.h>
using namespace std;
int n,pt1,pt2;
long double sum1,sum2,a[100005],b[100005],ans;
int main(){
ios::sync_with_stdio(false);
cin >> n;
for (int i=1;i<=n;i++){
cin >> a[i] >> b[i];
}
sort(a+1,a+1+n); sort(b+1,b+1+n);
reverse(a+1,a+1+n); reverse(b+1,b+1+n);
while (pt1 < n || pt2 < n){
if (pt2 == n || (pt1 < n && sum1 < sum2)){
pt1++;
sum1+=a[pt1];
}
else
{
pt2++;
sum2+=b[pt2];
}
ans=max(ans,min(sum1,sum2)-pt1-pt2);
}
cout << fixed << setprecision(4) << ans << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
492 KB |
Output is correct |
12 |
Correct |
2 ms |
364 KB |
Output is correct |
13 |
Correct |
2 ms |
364 KB |
Output is correct |
14 |
Correct |
2 ms |
364 KB |
Output is correct |
15 |
Correct |
2 ms |
364 KB |
Output is correct |
16 |
Correct |
2 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
492 KB |
Output is correct |
12 |
Correct |
2 ms |
364 KB |
Output is correct |
13 |
Correct |
2 ms |
364 KB |
Output is correct |
14 |
Correct |
2 ms |
364 KB |
Output is correct |
15 |
Correct |
2 ms |
364 KB |
Output is correct |
16 |
Correct |
2 ms |
364 KB |
Output is correct |
17 |
Correct |
103 ms |
4844 KB |
Output is correct |
18 |
Correct |
107 ms |
4972 KB |
Output is correct |
19 |
Correct |
112 ms |
4844 KB |
Output is correct |
20 |
Correct |
104 ms |
4864 KB |
Output is correct |
21 |
Correct |
121 ms |
5356 KB |
Output is correct |
22 |
Correct |
107 ms |
4940 KB |
Output is correct |
23 |
Correct |
106 ms |
4844 KB |
Output is correct |
24 |
Correct |
103 ms |
4844 KB |
Output is correct |
25 |
Correct |
105 ms |
4844 KB |
Output is correct |
26 |
Correct |
111 ms |
5356 KB |
Output is correct |