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>
using namespace std;
int TIME = clock();
#define file \
freopen("in.txt" , "r" , stdin); \
freopen("out.txt" , "w" , stdout);
void test_case () {
int n;
cin >> n;
priority_queue<long double> p[2];
for (int i = 0;i < n;i ++) {
long double a , b;
cin >> a >> b;
p[0].push(a);
p[1].push(b);
}
long double res = 0 , d[2] = {0 , 0};
for (int i = 1;i <= n * 2;i ++) {
if (p[0].size() == 0) {
d[1] += p[1].top();
p[1].pop();
} else if (p[1].size() == 0) {
d[0] += p[0].top();
p[0].pop();
} else if (d[0] <= d[1]) {
d[0] += p[0].top();
p[0].pop();
} else {
d[1] += p[1].top();
p[1].pop();
}
res = max(res , min(d[0] , d[1]) - i);
}
cout.precision(4);
cout << fixed << res << "\n";
}
int32_t main () {
/// file
int t = 1;
// cin >> t;
while (t --) {
test_case();
}
cerr << "\nTime elapsed: " << (clock() - TIME) * 1000.0 / CLOCKS_PER_SEC << " ms\n";
return 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... |