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(){
int n; cin >> n;
vector<double> a, b;
for(int i = 0; i < n; i++){
double u, v; cin >> u >> v;
a.push_back(u); b.push_back(v);
}
sort(a.begin(), a.end(), [](double x, double y){ return x > y; });
sort(b.begin(), b.end(), [](double x, double y){ return x > y; });
vector<double> sa(n + 1), sb(n + 1);
for(int i = 0; i < n; i++) sa[i + 1] = sa[i] + a[i];
for(int i = 0; i < n; i++) sb[i + 1] = sb[i] + b[i];
int L = 0, R = 0;
double ans = 0;
while(L < n || R < n){
if(R == n || L < n && sa[L] < sb[R]) L++;
else R++;
ans = max(ans, min(sa[L], sb[R]) - (L + R));
}
cout << fixed << setprecision(4) << ans << endl;
}
Compilation message (stderr)
sure.cpp: In function 'int32_t main()':
sure.cpp:24:24: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
24 | if(R == n || L < n && sa[L] < sb[R]) L++;
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |