This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// Success consists of going from failure to failure without loss of enthusiasm
#include <bits/stdc++.h>
using namespace std;
#define nl '\n'
#define pb push_back
#define sz(x) int(x.size())
using db = double;
using ll = long long;
template<class T> using V = vector<T>;
using vi = V<int>;
const int MUL = int(1e4);
int main() {
cin.tie(0)->sync_with_stdio(0);
int N; cin >> N;
vi A(N), B(N); for(int i = 0; i < N; i++) {
db x, y; cin >> x >> y;
A[i] = int(MUL * x), B[i] = int(MUL * y);
}
sort(rbegin(A), rend(A)); sort(rbegin(B), rend(B));
ll sa = A[0], sb = B[0], ans = 0; int a = 1, b = 1;
while(1) {
int x = a + b;
ans = max(ans, min(sa - x * MUL, sb - x * MUL));
// cout << ans << " " << sa << " " << sb << " " << x << endl;
if (sa == sb) {
if (max(a, b) == N) break;
sa += A[a++];
sb += B[b++];
} else if (sa < sb) {
if (a == N) break;
sa += A[a++];
} else if (sb > sa) {
if (b == N) break;
sb += B[b++];
} else break;
}
printf("%.4f", db(ans) / db(MUL));
exit(0-0);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |