#include <cstdio>
#include <algorithm>
#include <numeric>
#include <functional>
#define MAXN 100100
double a[MAXN];
double b[MAXN];
double pa[MAXN];
double pb[MAXN];
int n;
int main(void) {
double best = 0;
scanf("%d", &n);
for(int i = 0; i < n; i++) {
scanf("%lf %lf", &a[i], &b[i]);
}
std::sort(a, a + n, std::greater<double>());
std::sort(b, b + n, std::greater<double>());
std::partial_sum(a, a + n, pa);
std::partial_sum(b, b + n, pb);
for(int i = 0; i < n; i++) {
double x = pa[i];
double y1 = 0, y2 = 0;
auto it = std::upper_bound(pb, pb + n, x);
if(it != pb + n) y1 = std::min(x, *it) - std::distance(pb, it) - i - 2;
if(it != pb) it = std::prev(it);
y2 = std::min(x, *it) - std::distance(pb, it) - i - 2;
best = std::max(best, std::max(y1, y2));
}
printf("%.4lf", best);
return 0;
}
Compilation message
sure.cpp: In function 'int main()':
sure.cpp:13:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
13 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
sure.cpp:15:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
15 | scanf("%lf %lf", &a[i], &b[i]);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
284 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
284 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
284 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
280 KB |
Output is correct |
12 |
Correct |
1 ms |
272 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
296 KB |
Output is correct |
15 |
Correct |
1 ms |
296 KB |
Output is correct |
16 |
Correct |
1 ms |
296 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
284 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
284 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
280 KB |
Output is correct |
12 |
Correct |
1 ms |
272 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
296 KB |
Output is correct |
15 |
Correct |
1 ms |
296 KB |
Output is correct |
16 |
Correct |
1 ms |
296 KB |
Output is correct |
17 |
Correct |
85 ms |
4676 KB |
Output is correct |
18 |
Correct |
88 ms |
4728 KB |
Output is correct |
19 |
Correct |
66 ms |
4932 KB |
Output is correct |
20 |
Correct |
63 ms |
4680 KB |
Output is correct |
21 |
Correct |
66 ms |
5064 KB |
Output is correct |
22 |
Correct |
71 ms |
4756 KB |
Output is correct |
23 |
Correct |
75 ms |
4764 KB |
Output is correct |
24 |
Correct |
67 ms |
4656 KB |
Output is correct |
25 |
Correct |
69 ms |
4708 KB |
Output is correct |
26 |
Correct |
78 ms |
5072 KB |
Output is correct |