#include <bits/stdc++.h>
using namespace std;
constexpr int NMAX = 1e5 + 5;
int N;
double A[NMAX];
double B[NMAX];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> N;
for (int i = 1; i <= N; ++ i ) {
cin >> A[i] >> B[i];
}
sort(A+1, A+N+1);
sort(B+1, B+N+1);
for (int i = N - 1; i >= 1; -- i )
B[i] += B[i+1];
double answer = 0;
double sumA = 0;
for (int i = N+1; i >= 1; -- i ) {
sumA += A[i];
int paidA = (N - i + 1);
int st = 1, dr = N;
int pos = N + 1;
while (st <= dr) {
int mij = (st + dr) / 2;
double curr_case = min(sumA - paidA - (N - mij + 1), B[mij] - paidA - (N - mij + 1));
double ant_case = min(sumA - paidA - (N - (mij+1) + 1), B[mij+1] - paidA - (N - (mij+1) + 1));
if (curr_case >= ant_case) {
pos = mij;
dr = mij - 1;
}
else st = mij + 1;
}
double sumB = B[pos];
int paidB = N - pos + 1;
answer = max(answer, min(sumA - paidA - paidB, sumB - paidA - paidB));
}
cout << setprecision(4) << fixed << answer << '\n';
return 0;
}
# |
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 |
468 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 |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 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 |
348 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 |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 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 |
348 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 |
64 ms |
3368 KB |
Output is correct |
18 |
Correct |
64 ms |
3152 KB |
Output is correct |
19 |
Correct |
70 ms |
3404 KB |
Output is correct |
20 |
Correct |
63 ms |
3364 KB |
Output is correct |
21 |
Correct |
67 ms |
3660 KB |
Output is correct |
22 |
Correct |
67 ms |
3152 KB |
Output is correct |
23 |
Correct |
64 ms |
3192 KB |
Output is correct |
24 |
Correct |
64 ms |
3356 KB |
Output is correct |
25 |
Correct |
67 ms |
3160 KB |
Output is correct |
26 |
Correct |
67 ms |
3692 KB |
Output is correct |