#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin>>n;
vector<double> v1,v2;
for(int i=0;i<n;i++) {
double a,b;
cin>>a>>b;
v1.push_back(a);
v2.push_back(b);
}
sort(v1.begin(),v1.end(),greater<double>());
sort(v2.begin(),v2.end(),greater<double>());
double s1[n],s2[n];
s1[0]=v1[0];
s2[0]=v2[0];
for(int i=1;i<n;i++) {
s1[i]=s1[i-1]+v1[i];
s2[i]=s2[i-1]+v2[i];
}
double res=0;
int ptr=0;
for(int i=0;i<n;i++) {
while(ptr+1<n && s1[i]>s2[ptr]) {
int t=i+ptr+2;
res=max(res,min(s1[i],s2[ptr])-t);
ptr++;
}
int t=i+ptr+2;
res=max(res,min(s1[i],s2[ptr])-t);
}
cout<<fixed<<setprecision(4);
cout<<res<<endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
256 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
256 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
256 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
256 KB |
Output is correct |
12 |
Correct |
6 ms |
384 KB |
Output is correct |
13 |
Correct |
6 ms |
384 KB |
Output is correct |
14 |
Correct |
7 ms |
384 KB |
Output is correct |
15 |
Correct |
8 ms |
384 KB |
Output is correct |
16 |
Correct |
6 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
256 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
256 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
256 KB |
Output is correct |
12 |
Correct |
6 ms |
384 KB |
Output is correct |
13 |
Correct |
6 ms |
384 KB |
Output is correct |
14 |
Correct |
7 ms |
384 KB |
Output is correct |
15 |
Correct |
8 ms |
384 KB |
Output is correct |
16 |
Correct |
6 ms |
384 KB |
Output is correct |
17 |
Correct |
185 ms |
5088 KB |
Output is correct |
18 |
Correct |
175 ms |
4960 KB |
Output is correct |
19 |
Correct |
172 ms |
4960 KB |
Output is correct |
20 |
Correct |
175 ms |
4960 KB |
Output is correct |
21 |
Correct |
197 ms |
5600 KB |
Output is correct |
22 |
Correct |
173 ms |
5092 KB |
Output is correct |
23 |
Correct |
177 ms |
4960 KB |
Output is correct |
24 |
Correct |
177 ms |
5092 KB |
Output is correct |
25 |
Correct |
175 ms |
5116 KB |
Output is correct |
26 |
Correct |
195 ms |
5432 KB |
Output is correct |