#include <bits/stdc++.h>
using namespace std;
//#define FILE_IO
int N;
double a[100005], b[100005];
int main()
{
#ifdef FILE_IO
freopen("1.in", "r", stdin);
freopen("1.out", "w", stdout);
#endif
cin >> N;
for(int i = 1; i <= N; i++)
cin >> a[i] >> b[i];
sort(a + 1, a + N + 1); reverse(a + 1, a + N + 1);
sort(b + 1, b + N + 1); reverse(b + 1, b + N + 1);
int p1 = 1, p2 = 1;
double prfA = 0.0, prfB = 0.0;
double ans = 0.0;
int cnt = 0;
while(p1 <= N || p2 <= N)
{
if(prfA < prfB && p1 <= N)
{
prfA += a[p1];
p1++;
cnt++;
}
else if(p2 <= N)
{
prfB += b[p2];
p2++;
cnt++;
}
else
break;
ans = max(ans, min(prfA, prfB) - cnt);
}
cout << fixed << setprecision(4) << ans << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
496 KB |
Output is correct |
3 |
Correct |
2 ms |
496 KB |
Output is correct |
4 |
Correct |
2 ms |
496 KB |
Output is correct |
5 |
Correct |
2 ms |
496 KB |
Output is correct |
6 |
Correct |
2 ms |
568 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
496 KB |
Output is correct |
3 |
Correct |
2 ms |
496 KB |
Output is correct |
4 |
Correct |
2 ms |
496 KB |
Output is correct |
5 |
Correct |
2 ms |
496 KB |
Output is correct |
6 |
Correct |
2 ms |
568 KB |
Output is correct |
7 |
Correct |
2 ms |
712 KB |
Output is correct |
8 |
Correct |
2 ms |
712 KB |
Output is correct |
9 |
Correct |
2 ms |
736 KB |
Output is correct |
10 |
Correct |
2 ms |
736 KB |
Output is correct |
11 |
Correct |
2 ms |
736 KB |
Output is correct |
12 |
Correct |
3 ms |
736 KB |
Output is correct |
13 |
Correct |
4 ms |
736 KB |
Output is correct |
14 |
Correct |
3 ms |
776 KB |
Output is correct |
15 |
Correct |
5 ms |
776 KB |
Output is correct |
16 |
Correct |
4 ms |
988 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
496 KB |
Output is correct |
3 |
Correct |
2 ms |
496 KB |
Output is correct |
4 |
Correct |
2 ms |
496 KB |
Output is correct |
5 |
Correct |
2 ms |
496 KB |
Output is correct |
6 |
Correct |
2 ms |
568 KB |
Output is correct |
7 |
Correct |
2 ms |
712 KB |
Output is correct |
8 |
Correct |
2 ms |
712 KB |
Output is correct |
9 |
Correct |
2 ms |
736 KB |
Output is correct |
10 |
Correct |
2 ms |
736 KB |
Output is correct |
11 |
Correct |
2 ms |
736 KB |
Output is correct |
12 |
Correct |
3 ms |
736 KB |
Output is correct |
13 |
Correct |
4 ms |
736 KB |
Output is correct |
14 |
Correct |
3 ms |
776 KB |
Output is correct |
15 |
Correct |
5 ms |
776 KB |
Output is correct |
16 |
Correct |
4 ms |
988 KB |
Output is correct |
17 |
Correct |
192 ms |
3784 KB |
Output is correct |
18 |
Correct |
161 ms |
5084 KB |
Output is correct |
19 |
Correct |
165 ms |
6648 KB |
Output is correct |
20 |
Correct |
208 ms |
7884 KB |
Output is correct |
21 |
Correct |
182 ms |
9600 KB |
Output is correct |
22 |
Correct |
168 ms |
11132 KB |
Output is correct |
23 |
Correct |
169 ms |
12372 KB |
Output is correct |
24 |
Correct |
159 ms |
13692 KB |
Output is correct |
25 |
Correct |
158 ms |
15060 KB |
Output is correct |
26 |
Correct |
188 ms |
16880 KB |
Output is correct |