#include <bits/stdc++.h>
#define int long long
using namespace std;
namespace std {
template <typename T> ostream &operator<<(ostream &out, const vector<T> &vec) {
out << "[";
for (int i = 0; i < (int)vec.size(); ++i) {
out << vec[i];
if (i + 1 < (int)vec.size())
out << ", ";
}
return out << "]";
}
} // namespace std
void dbg_out() { cout << endl; }
template <typename Head, typename... Tail> void dbg_out(Head H, Tail... T) {
cout << ' ' << H;
dbg_out(T...);
}
#ifdef DEBUG
#define dbg(...) cout << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif
signed main(void) {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<double> a(n), b(n);
for (int i = 0; i < n; ++i) {
cin >> a[i] >> b[i];
}
sort(a.begin(), a.end());
sort(b.begin(), b.end());
vector<double> suffA(n + 1), suffB(n + 1);
for (int i = n - 1; i >= 0; --i) {
suffA[i] = suffA[i + 1] + a[i];
suffB[i] = suffB[i + 1] + b[i];
}
double sol = 0;
vector<double> solA(n + 1), solB(n + 1);
for (int takeA = 0; takeA <= n; ++takeA)
solA[takeA] = suffA[n - takeA];
for (int takeB = 0; takeB <= n; ++takeB)
solB[takeB] = suffB[n - takeB];
// A min
for (int takeA = 1; takeA <= n; ++takeA) {
double xa = solA[takeA];
int lo = lower_bound(solB.begin(), solB.end(), xa) - solB.begin();
if (lo == n + 1)
continue;
sol = max(sol, xa - lo - takeA);
};
// B min
for (int takeB = 1; takeB <= n; ++takeB) {
double xb = solB[takeB];
int lo = lower_bound(solA.begin(), solA.end(), xb) - solA.begin();
if (lo == n + 1)
continue;
sol = max(sol, xb - takeB - lo);
}
printf("%.4lf", sol);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 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 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 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 |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
340 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 |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 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 |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
340 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 |
86 ms |
5020 KB |
Output is correct |
18 |
Correct |
79 ms |
6320 KB |
Output is correct |
19 |
Correct |
84 ms |
6392 KB |
Output is correct |
20 |
Correct |
81 ms |
6348 KB |
Output is correct |
21 |
Correct |
86 ms |
6728 KB |
Output is correct |
22 |
Correct |
83 ms |
6448 KB |
Output is correct |
23 |
Correct |
79 ms |
6360 KB |
Output is correct |
24 |
Correct |
80 ms |
6324 KB |
Output is correct |
25 |
Correct |
78 ms |
6348 KB |
Output is correct |
26 |
Correct |
88 ms |
6736 KB |
Output is correct |