#include<bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
#define sz(x) int((x).size())
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> ii;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int Random(int l, int r) {
return uniform_int_distribution<int>(l, r)(rng);
}
const int MAXN = 100005;
double a[MAXN], b[MAXN];
int nArr;
void process(void) {
cin >> nArr;
for (int i = 1; i <= nArr; ++i)
cin >> a[i] >> b[i];
sort(a + 1, a + nArr + 1);
sort(b + 1, b + nArr + 1);
double res(0), sumA(0), sumB(0);
int i(nArr), j(nArr);
while(max(i, j) > 0) {
if(j == 0 || i > 0 && sumA <= sumB) {
sumA += a[i--];
} else {
sumB += b[j--];
}
res = max(res, min(sumA, sumB) - 2 * nArr + i + j);
}
cout << setprecision(4) << fixed << res << '\n';
}
int main(void) {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
process();
return 0;
}
Compilation message
sure.cpp: In function 'void process()':
sure.cpp:32:28: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
32 | if(j == 0 || i > 0 && sumA <= sumB) {
| ~~~~~~^~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
472 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
472 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
468 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
472 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
468 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
54 ms |
3168 KB |
Output is correct |
18 |
Correct |
55 ms |
3152 KB |
Output is correct |
19 |
Correct |
57 ms |
3196 KB |
Output is correct |
20 |
Correct |
62 ms |
3368 KB |
Output is correct |
21 |
Correct |
58 ms |
3748 KB |
Output is correct |
22 |
Correct |
54 ms |
3168 KB |
Output is correct |
23 |
Correct |
66 ms |
3384 KB |
Output is correct |
24 |
Correct |
54 ms |
3256 KB |
Output is correct |
25 |
Correct |
55 ms |
3168 KB |
Output is correct |
26 |
Correct |
60 ms |
3756 KB |
Output is correct |