#include <bits/stdc++.h>
#define FOR(i, l, r) for(int i=(l); i<=(r); ++i)
#define REP(i, l, r) for(int i=(l); i<(r); ++i)
#define FORD(i, r, l) for(int i=(r); i>=(l); --i)
#define REPD(i, r, l) for(int i=(r)-1; i>=(l); --i)
using namespace std;
const int N = 1e5 + 5;
int n;
long double a[N], b[N];
void Enter() {
cin >> n;
FOR(i, 1, n) cin >> a[i] >> b[i];
}
void Process() {
sort(a + 1, a + n + 1, greater<long double>());
sort(b + 1, b + n + 1, greater<long double>());
long double res = 0, sumL = 0, sumR = 0;
for(int i = 1, j = 1; i <= n || j <= n; ) {
if (j > n || i <= n && sumL < sumR) sumL += a[i++];
else sumR += b[j++];
res = max(res, min(sumL, sumR) - (i + j - 2));
}
cout << setprecision(4) << fixed << res;
}
int main()
{
#define file "sure"
if (fopen(file".inp", "r")) {
freopen(file".inp", "r", stdin);
freopen(file".out", "w", stdout);
}
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
Enter();
Process();
}
Compilation message
sure.cpp: In function 'void Process()':
sure.cpp:22:29: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
22 | if (j > n || i <= n && sumL < sumR) sumL += a[i++];
| ~~~~~~~^~~~~~~~~~~~~~
sure.cpp: In function 'int main()':
sure.cpp:33:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
33 | freopen(file".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
sure.cpp:34:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
34 | freopen(file".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
324 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
324 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
328 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
2 ms |
468 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 |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
324 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
328 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
2 ms |
468 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 |
340 KB |
Output is correct |
17 |
Correct |
85 ms |
4772 KB |
Output is correct |
18 |
Correct |
87 ms |
4824 KB |
Output is correct |
19 |
Correct |
85 ms |
4812 KB |
Output is correct |
20 |
Correct |
98 ms |
4812 KB |
Output is correct |
21 |
Correct |
89 ms |
5172 KB |
Output is correct |
22 |
Correct |
78 ms |
4688 KB |
Output is correct |
23 |
Correct |
101 ms |
4768 KB |
Output is correct |
24 |
Correct |
82 ms |
4748 KB |
Output is correct |
25 |
Correct |
84 ms |
4820 KB |
Output is correct |
26 |
Correct |
90 ms |
5116 KB |
Output is correct |