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;
bool ord(long double a, long double b){
return a > b;
}
int main(){
int n; cin >> n;
vector <long double> f(n), s(n);
for(int i = 0; i<n; i++) cin >> f[i] >> s[i];
sort(f.begin(), f.end(), ord);
sort(s.begin(), s.end(), ord);
long double ans = 0, i = 0, j = 0, si = 0, sj = 0;
if(f[i] > s[i]){
i = 1;
si += f[0];
}else{
j = 1;
sj += s[0];
}
ans = max(ans, min(sj, si) - (i+j));
while(i < n && j < n){
if(sj < si){
sj += s[j];
j++;
}else{
si += f[i];
i++;
}
ans = max(ans, min(sj, si) - (i+j));
}
cout.precision(4);
cout.setf(ios::fixed);
cout << ans << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |