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 <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <string>
#include <time.h>
#include <stack>
#include <queue>
#include <random>
#include <fstream>
#define endl '\n'
#define flush fflush(stdout), cout.flush()
#define fast ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define debug cout << "ok" << endl
#define finish(x) return cout << x << endl, 0
typedef long long ll;
typedef long double ldb;
const int md = 1e9 + 7, inf = 1e9 + 7;
const ll hs = 199;
const ldb eps = 1e-9, pi = acos(-1);
using namespace std;
int n;
vector<double> a, b;
double mx = 0;
bool cmp(double x, double y) {
return x > y;
}
int main() {
cin >> n;
a.resize(n);
b.resize(n);
for (int i = 0; i < n; i++) cin >> a[i] >> b[i];
sort(a.begin(), a.end(), cmp);
sort(b.begin(), b.end(), cmp);
int nxt1 = 0, nxt2 = 0;
double v1 = 0, v2 = 0;
for (int tot = 1; tot <= 2 * n; tot++) {
if (nxt1 == n) v2 += b[nxt2++];
else if (nxt2 == n) v1 += a[nxt1++];
else if (v1 > v2) v2 += b[nxt2++];
else v1 += a[nxt1++];
mx = max(mx, min(v1, v2) - tot);
}
printf("%.4lf", (double)mx);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |