#include <iostream>
#include <iomanip>
#include <algorithm>
using namespace std;
int main(){
cin.tie(0)->sync_with_stdio(0);
cout << fixed << setprecision(4);
int n; cin >> n;
double a[n], b[n];
for (int i = 0; i < n; i++){
cin >> a[i] >> b[i];
}
sort(a, a + n, greater<double>());
sort(b, b + n, greater<double>());
double prefa[n + 1]{}, prefb[n + 1]{};
for (int i = 0; i < n; i++){
prefa[i + 1] = prefa[i] + a[i];
prefb[i + 1] = prefb[i] + b[i];
}
double ans = 0;
int pa = 0, pb = 0;
while (pa <= n && pb <= n){
if (prefa[pa] < prefb[pb])
pa++;
else
pb++;
ans = max(ans, min(prefa[pa], prefb[pb]) - pa - pb);
}
while (pa <= n){
pa++;
ans = max(ans, min(prefa[pa], prefb[pb]) - pa - pb);
}
while (pb <= n){
pb++;
ans = max(ans, min(prefa[pa], prefb[pb]) - pa - pb);
}
cout << ans << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
316 KB |
Output is correct |
4 |
Correct |
0 ms |
316 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
316 KB |
Output is correct |
4 |
Correct |
0 ms |
316 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
320 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
316 KB |
Output is correct |
4 |
Correct |
0 ms |
316 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
320 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
70 ms |
4776 KB |
Output is correct |
18 |
Correct |
65 ms |
4792 KB |
Output is correct |
19 |
Correct |
67 ms |
4772 KB |
Output is correct |
20 |
Correct |
67 ms |
4772 KB |
Output is correct |
21 |
Correct |
72 ms |
5048 KB |
Output is correct |
22 |
Correct |
65 ms |
4680 KB |
Output is correct |
23 |
Correct |
67 ms |
4680 KB |
Output is correct |
24 |
Correct |
65 ms |
4792 KB |
Output is correct |
25 |
Correct |
66 ms |
4768 KB |
Output is correct |
26 |
Correct |
76 ms |
5056 KB |
Output is correct |