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 <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
using namespace std;
bool srt(float a, float b) {
return a > b;
}
int main() {
int n, f = 0, s = 0;
float fsum = 0, ssum = 0, res = 0;
cin >> n;
vector<float> a(n), b(n);
for(int i = 0; i < n; i++) cin >> a[i] >> b[i];
sort(a.begin(), a.end(), srt);
sort(b.begin(), b.end(), srt);
//Sa <= Sb
while(f < n && s < n) {
while(fsum <= ssum && f < n) {
fsum+=a[f];
f++;
if(fsum <= ssum) {
res = max(res, fsum-f-s);
}
}
while(fsum > ssum && s < n) {
ssum+=b[s];
s++;
}
if(fsum <= ssum) res = max(res, fsum-f-s);
}
//Sb <= Sa
f = 0, s = 0, fsum = 0, ssum = 0;
while(f < n && s < n) {
while(ssum <= fsum && s < n) {
ssum+=b[s];
s++;
if(ssum <= fsum) res = max(res, ssum-f-s);
}
while(ssum > fsum && f < n) {
fsum+=a[s];
f++;
}
if(ssum <= fsum) res = max(res, ssum-f-s);
}
cout << fixed << setprecision(4) << res << "\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... |