This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |