#include <bits/stdc++.h>
using namespace std;
const int N = 100*1000+5;
pair<double,double> a[N];
double prefa[N],prefb[N];
int main()
{
ios_base::sync_with_stdio(false);
int n;
cin>>n;
for(int i = 1;i<=n;i++) cin>>a[i].first>>a[i].second;
sort(a+1,a+1+n);
reverse(a+1,a+1+n);
for(int i = 1;i<=n;i++) prefa[i] = prefa[i-1]+a[i].first;
for(int i = 1;i<=n;i++) swap(a[i].first,a[i].second);
sort(a+1,a+1+n);
reverse(a+1,a+1+n);
for(int i = 1;i<=n;i++) prefb[i] = prefb[i-1]+a[i].first;
double ans = 0;
int i = 0;
int j = 0;
double x,y;
x = y = 0;
while(1){
// cout<<i<<" "<<j<<endl;
if(i!=n){
i++;
x = prefa[i];
ans = max(ans,min(x,y)-(i+j));
}
while(x<=y){
if(i == n) break;
i++;
x=prefa[i];
ans = max(ans,min(x,y)-(i+j));
}
ans = max(ans,min(x,y)-(i+j));
if(j!=n){
j++;
y = prefb[j];
ans = max(ans,min(x,y)-(i+j));
}
while(y<=x){
if(j == n) break;
j++;
y=prefb[j];
ans = max(ans,min(x,y)-(i+j));
}
ans = max(ans,min(x,y)-(i+j));
if(i == n && j == n) break;
}
printf("%.4lf",(double)ans);
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
356 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Correct |
3 ms |
384 KB |
Output is correct |
13 |
Correct |
3 ms |
384 KB |
Output is correct |
14 |
Correct |
3 ms |
384 KB |
Output is correct |
15 |
Correct |
3 ms |
384 KB |
Output is correct |
16 |
Correct |
3 ms |
512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
356 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Correct |
3 ms |
384 KB |
Output is correct |
13 |
Correct |
3 ms |
384 KB |
Output is correct |
14 |
Correct |
3 ms |
384 KB |
Output is correct |
15 |
Correct |
3 ms |
384 KB |
Output is correct |
16 |
Correct |
3 ms |
512 KB |
Output is correct |
17 |
Correct |
88 ms |
3572 KB |
Output is correct |
18 |
Correct |
96 ms |
4832 KB |
Output is correct |
19 |
Correct |
90 ms |
4856 KB |
Output is correct |
20 |
Correct |
88 ms |
4856 KB |
Output is correct |
21 |
Correct |
92 ms |
5240 KB |
Output is correct |
22 |
Correct |
91 ms |
4944 KB |
Output is correct |
23 |
Correct |
94 ms |
4896 KB |
Output is correct |
24 |
Correct |
88 ms |
4856 KB |
Output is correct |
25 |
Correct |
89 ms |
4856 KB |
Output is correct |
26 |
Correct |
94 ms |
5352 KB |
Output is correct |