#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
signed main() {
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
///freopen ("input.txt", "r", stdin);
int n;
cin >> n;
vector<ld> s1(n + 1, 0), s2(n + 1, 0);
{
vector<ld> a(n), b(n);
for (int i = 0; i < n; i++) {
cin >> a[i] >> b[i];
}
sort(a.rbegin(), a.rend());
sort(b.rbegin(), b.rend());
for (int i = 0; i < n; i++) {
s1[i + 1] = s1[i] + a[i];
s2[i + 1] = s2[i] + b[i];
}
}
ld sol = 0;
for (int iter = 0; iter < 2; iter++) {
swap(s1, s2);
vector<ld> pref(n + 1);
for (int i = 0; i <= n; i++) {
pref[i] = s2[i] - i;
if (i - 1 >= 0) {
pref[i] = max(pref[i - 1], pref[i]);
}
}
int t2 = 0;
for (int t1 = 0; t1 <= n; t1++) {
while (t2 + 1 <= n && s2[t2 + 1] <= s1[t1]) {
t2++;
}
if (s2[t2] <= s1[t1]) {
sol = max(sol, pref[t2] - t1);
}
}
}
cout << fixed << setprecision(4) << sol << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 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 |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 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 |
2 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 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 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 |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 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 |
2 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 |
91 ms |
6588 KB |
Output is correct |
18 |
Correct |
90 ms |
7868 KB |
Output is correct |
19 |
Correct |
92 ms |
7960 KB |
Output is correct |
20 |
Correct |
91 ms |
7852 KB |
Output is correct |
21 |
Correct |
100 ms |
8252 KB |
Output is correct |
22 |
Correct |
93 ms |
7856 KB |
Output is correct |
23 |
Correct |
88 ms |
7868 KB |
Output is correct |
24 |
Correct |
89 ms |
7896 KB |
Output is correct |
25 |
Correct |
90 ms |
7868 KB |
Output is correct |
26 |
Correct |
95 ms |
8328 KB |
Output is correct |