#include<bits/stdc++.h>
using namespace std;
const int nmax=1e5+42;
int n;
double a[nmax],b[nmax];
int main()
{
cin>>n;
for(int i=1;i<=n;i++)cin>>a[i]>>b[i];
sort(a+1,a+n+1);
sort(b+1,b+n+1);
int i=n,j=n;
double sum_a=0,sum_b=0,ret=0;
while(i>=1||j>=1)
{
if(i==0){sum_b+=b[j];j--;}
else if(j==0){sum_a+=a[i];i--;}
else
{
if(sum_a<sum_b){sum_a+=a[i];i--;}
else {sum_b+=b[j];j--;}
}
ret=max(ret,min(sum_a,sum_b)-(n-i)-(n-j));
//cout<<sum_a<<" "<<sum_b<<" "<<i<<" "<<j<<" "<<min(sum_a,sum_b)-(n-i)-(n-j)<<endl;
}
printf("%.4f",ret);
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
256 KB |
Output is correct |
2 |
Correct |
4 ms |
256 KB |
Output is correct |
3 |
Correct |
5 ms |
256 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 |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
256 KB |
Output is correct |
2 |
Correct |
4 ms |
256 KB |
Output is correct |
3 |
Correct |
5 ms |
256 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 |
256 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 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 |
384 KB |
Output is correct |
12 |
Correct |
6 ms |
384 KB |
Output is correct |
13 |
Correct |
6 ms |
384 KB |
Output is correct |
14 |
Correct |
6 ms |
384 KB |
Output is correct |
15 |
Correct |
6 ms |
384 KB |
Output is correct |
16 |
Correct |
6 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
256 KB |
Output is correct |
2 |
Correct |
4 ms |
256 KB |
Output is correct |
3 |
Correct |
5 ms |
256 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 |
256 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 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 |
384 KB |
Output is correct |
12 |
Correct |
6 ms |
384 KB |
Output is correct |
13 |
Correct |
6 ms |
384 KB |
Output is correct |
14 |
Correct |
6 ms |
384 KB |
Output is correct |
15 |
Correct |
6 ms |
384 KB |
Output is correct |
16 |
Correct |
6 ms |
384 KB |
Output is correct |
17 |
Correct |
180 ms |
3264 KB |
Output is correct |
18 |
Correct |
173 ms |
3192 KB |
Output is correct |
19 |
Correct |
185 ms |
3192 KB |
Output is correct |
20 |
Correct |
189 ms |
3320 KB |
Output is correct |
21 |
Correct |
195 ms |
3576 KB |
Output is correct |
22 |
Correct |
174 ms |
3192 KB |
Output is correct |
23 |
Correct |
180 ms |
3448 KB |
Output is correct |
24 |
Correct |
175 ms |
3192 KB |
Output is correct |
25 |
Correct |
173 ms |
3192 KB |
Output is correct |
26 |
Correct |
196 ms |
3576 KB |
Output is correct |