# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
778680 | RecursiveCo | Sure Bet (CEOI17_sure) | C++14 | 1 ms | 212 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// CF template, version 3.0
#include <bits/stdc++.h>
using namespace std;
#define improvePerformance ios_base::sync_with_stdio(false); cin.tie(0)
#define getTest int t; cin >> t
#define eachTest for (int _var=0;_var<t;_var++)
#define get(name) int (name); cin >> (name)
#define out(o) cout << (o)
#define getList(cnt, name) vector<int> (name); for (int _=0;_<(cnt);_++) { get(a); (name).push_back(a); }
#define sortl(name) sort((name).begin(), (name).end())
#define rev(name) reverse((name).begin(), (name).end())
#define forto(name, var) for (int (var) = 0; (var) < (name); (var)++)
#define decision(b) if (b){out("YES");}else{out("NO");}
#define int long long int
signed main() {
improvePerformance;
get(n);
out(setprecision(4));
vector<double> A;
vector<double> B;
forto(n, i) {
double a, b;
cin >> a >> b;
A.push_back(a);
B.push_back(b);
}
sortl(A);
sortl(B);
rev(A);
rev(B);
vector<double> apref;
vector<double> bpref;
apref.push_back(0);
bpref.push_back(0);
forto(n, i) {
apref.push_back(apref.back() + A[i]);
bpref.push_back(bpref.back() + B[i]);
}
double ans = 0;
for (int b = 1; b <= 2 * n; b++) {
int l = 0;
int r = min(b, n);
double cur = 0;
while (r - l >= 1) {
int middle = (l + r) / 2;
double asum = apref[middle];
double bsum = bpref[b - middle];
if (asum <= bsum) l = middle + 1;
else r = middle;
}
cur = max(cur, bpref[b - l]);
cur = max(cur, apref[l - 1]);
ans = max(ans, cur - (double) (b));
}
out(ans);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |