# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1027198 | toan2602 | Sure Bet (CEOI17_sure) | C++14 | 55 ms | 2764 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.
#include<bits/stdc++.h>
using namespace std;
int n;
double a[100005], b[100005], pfs[100005];
void solve() {
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i] >> b[i];
sort(a+1,a+1+n, greater<>());
sort(b+1,b+1+n, greater<>());
for (int i = 1; i <= n; i++) pfs[i] = pfs[i-1] + b[i];
double ra, rb, res = 0;
ra = rb = 0;
for (int i = 1; i <= n; i++) {
ra += a[i], rb = 0;
int l = 1, r = n, mid, pos=n;
while(l <= r) {
mid = (l+r)/2;
if(pfs[mid] > ra) r = mid-1, pos = min(pos, mid);
else l = mid+1;
}
res = max(res, min(ra-i-pos, pfs[pos]-i-pos));
if(pos != 1) pos--, res = max(res, min(ra-i-pos, pfs[pos]-i-pos));
}
cout << fixed << setprecision(4) << res;
}
signed main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
if(fopen("input.inp","r")){
freopen("input.inp", "r", stdin);
freopen("output.out", "w", stdout);
}
int t = 1;
// cin >> t;
while(t--) {
solve();
}
}
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... |