#include <bits/stdc++.h>
using namespace std;
const int nmax = 1e5;
int n;
double a[nmax + 5], b[nmax + 5];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
#ifdef home
freopen("nr.in","r",stdin);
freopen("nr.out","w",stdout);
#endif // home
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>a[i]>>b[i];
}
sort(a+1,a+n+1,greater<double>());
sort(b+1,b+n+1,greater<double>());
double rez = 0;
double sum_a = 0, sum_b = 0;
int nra = 0, nrb = 0;
while(nra < n || nrb < n)
{
if(nrb == n || (nra < n && sum_a < sum_b))
{
++nra;
sum_a += a[nra];
}
else
{
++nrb;
sum_b += b[nrb];
}
rez = max(rez, min(sum_a, sum_b) - (nra + nrb));
}
cout<<fixed<<setprecision(4);
cout<<rez<<'\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
53 ms |
1884 KB |
Output is correct |
18 |
Correct |
54 ms |
3284 KB |
Output is correct |
19 |
Correct |
57 ms |
3164 KB |
Output is correct |
20 |
Correct |
55 ms |
3360 KB |
Output is correct |
21 |
Correct |
63 ms |
3664 KB |
Output is correct |
22 |
Correct |
65 ms |
3368 KB |
Output is correct |
23 |
Correct |
60 ms |
3160 KB |
Output is correct |
24 |
Correct |
55 ms |
3148 KB |
Output is correct |
25 |
Correct |
55 ms |
3208 KB |
Output is correct |
26 |
Correct |
58 ms |
3712 KB |
Output is correct |