#include <bits/stdc++.h>
using namespace std;
int32_t main(){
int n; cin >> n;
vector<double> a, b;
for(int i = 0; i < n; i++){
double u, v; cin >> u >> v;
a.push_back(u); b.push_back(v);
}
sort(a.begin(), a.end(), [](double x, double y){ return x > y; });
sort(b.begin(), b.end(), [](double x, double y){ return x > y; });
vector<double> sa(n + 1), sb(n + 1);
for(int i = 0; i < n; i++) sa[i + 1] = sa[i] + a[i];
for(int i = 0; i < n; i++) sb[i + 1] = sb[i] + b[i];
int L = 0, R = 0;
double ans = 0;
while(L < n || R < n){
if(R == n || L < n && sa[L] < sb[R]) L++;
else R++;
ans = max(ans, min(sa[L], sb[R]) - (L + R));
}
cout << fixed << setprecision(4) << ans << endl;
}
Compilation message
sure.cpp: In function 'int32_t main()':
sure.cpp:24:24: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
24 | if(R == n || L < n && sa[L] < sb[R]) L++;
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
2 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
344 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 |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
2 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
104 ms |
5048 KB |
Output is correct |
18 |
Correct |
98 ms |
5128 KB |
Output is correct |
19 |
Correct |
97 ms |
5108 KB |
Output is correct |
20 |
Correct |
96 ms |
5372 KB |
Output is correct |
21 |
Correct |
112 ms |
5428 KB |
Output is correct |
22 |
Correct |
97 ms |
5048 KB |
Output is correct |
23 |
Correct |
98 ms |
5048 KB |
Output is correct |
24 |
Correct |
96 ms |
5052 KB |
Output is correct |
25 |
Correct |
97 ms |
5044 KB |
Output is correct |
26 |
Correct |
108 ms |
5308 KB |
Output is correct |