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;
int32_t main(){
cin.tie(NULL)->sync_with_stdio(false);
int n; cin >> n;
vector<double> a, b;
for(int i = 0; i < n; ++i){
double x, y; cin >> x >> y;
a.push_back(x);
b.push_back(y);
}
sort(a.rbegin(), a.rend());
sort(b.rbegin(), b.rend());
vector<double> sa, sb;
for(int i = 0; i < n; ++i){
sa.push_back(a[i]);
sb.push_back(b[i]);
if(i){
sa[i] += sa[i - 1];
sb[i] += sb[i - 1];
}
}
double ans = 0;
int ai = 0, bi = 0;
double sum_a = 0, sum_b = 0;
int tot = 0;
while(ai < n && bi < n){
if(ai == n){
tot++; sum_b = sb[bi++];
}else if(bi == n){
tot++; sum_a = sa[ai++];
}else{
tot++;
if(sum_b < sum_a) sum_b = sb[bi++];
else sum_a = sa[ai++];
}
double cost = min(sum_a, sum_b) - tot;
ans = max(ans, cost);
}
cout << setprecision(4) << fixed << ans << "\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |