#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
vector <double> a;
vector <double> b;
int main()
{
int n;
cin >> n;
double maxi=0;
for(int i=0;i<n;i++) {
double x,y;
cin >> x >> y;
a.push_back(x);
b.push_back(y);
}
sort(a.begin(),a.end());
sort(b.begin(),b.end());
int inda=n-2,indb=n-2;
double suma=a[n-1],sumb=b[n-1];
for(int i=2;i<=n*2;i++) {
maxi=max(maxi,min(suma,sumb)-i);
if(suma<sumb && inda>=0) {
suma+=a[inda];
inda-=1;
}
else if(indb>=0) {
sumb+=b[indb];
indb-=1;
}
else {
suma+=a[inda];
inda-=1;
}
}
maxi=max(maxi,min(suma,sumb)-2*n);
printf("%.4lf",maxi);
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
256 KB |
Output is correct |
3 |
Correct |
5 ms |
256 KB |
Output is correct |
4 |
Correct |
5 ms |
256 KB |
Output is correct |
5 |
Correct |
5 ms |
256 KB |
Output is correct |
6 |
Correct |
5 ms |
256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
256 KB |
Output is correct |
3 |
Correct |
5 ms |
256 KB |
Output is correct |
4 |
Correct |
5 ms |
256 KB |
Output is correct |
5 |
Correct |
5 ms |
256 KB |
Output is correct |
6 |
Correct |
5 ms |
256 KB |
Output is correct |
7 |
Correct |
6 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
256 KB |
Output is correct |
9 |
Correct |
5 ms |
256 KB |
Output is correct |
10 |
Correct |
5 ms |
256 KB |
Output is correct |
11 |
Correct |
5 ms |
300 KB |
Output is correct |
12 |
Correct |
7 ms |
256 KB |
Output is correct |
13 |
Correct |
7 ms |
376 KB |
Output is correct |
14 |
Correct |
7 ms |
376 KB |
Output is correct |
15 |
Correct |
7 ms |
376 KB |
Output is correct |
16 |
Correct |
7 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
256 KB |
Output is correct |
3 |
Correct |
5 ms |
256 KB |
Output is correct |
4 |
Correct |
5 ms |
256 KB |
Output is correct |
5 |
Correct |
5 ms |
256 KB |
Output is correct |
6 |
Correct |
5 ms |
256 KB |
Output is correct |
7 |
Correct |
6 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
256 KB |
Output is correct |
9 |
Correct |
5 ms |
256 KB |
Output is correct |
10 |
Correct |
5 ms |
256 KB |
Output is correct |
11 |
Correct |
5 ms |
300 KB |
Output is correct |
12 |
Correct |
7 ms |
256 KB |
Output is correct |
13 |
Correct |
7 ms |
376 KB |
Output is correct |
14 |
Correct |
7 ms |
376 KB |
Output is correct |
15 |
Correct |
7 ms |
376 KB |
Output is correct |
16 |
Correct |
7 ms |
376 KB |
Output is correct |
17 |
Correct |
181 ms |
2112 KB |
Output is correct |
18 |
Correct |
180 ms |
2180 KB |
Output is correct |
19 |
Correct |
182 ms |
2308 KB |
Output is correct |
20 |
Correct |
186 ms |
3424 KB |
Output is correct |
21 |
Correct |
205 ms |
3912 KB |
Output is correct |
22 |
Correct |
180 ms |
3424 KB |
Output is correct |
23 |
Correct |
182 ms |
3584 KB |
Output is correct |
24 |
Correct |
183 ms |
3428 KB |
Output is correct |
25 |
Correct |
184 ms |
3424 KB |
Output is correct |
26 |
Correct |
209 ms |
3952 KB |
Output is correct |