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>
#define ll long long
#define ff first
#define ss second
//#define pb push_back
using namespace std;
const int N = 1e6;
int n;
double A[N], B[N];
int main(){
cin >> n;
for(int i = 1; i <= n; i++){
cin >> A[i] >> B[i];
}
sort(A+1,A+1+n); reverse(A+1,A+1+n);
sort(B+1,B+1+n); reverse(B+1,B+1+n);
int pa = 2, pb = 2, cur = 2;
double answer = 0, cnt = min(A[1],B[1]) - 2, suma = A[1], sumb = B[1];
answer = max(answer,cnt);
while(pa <= n || pb <= n){
cur++;
if(pa > n){
sumb += B[pb]; pb++;
cnt = min(suma, sumb) - cur;
continue;
}
if(pb > n){
suma += A[pa]; pa++;
cnt = min(suma, sumb) - cur;
continue;
}
if(suma < sumb){
suma += A[pa]; pa++;
} else {
sumb += B[pb]; pb++;
}
cnt = min(suma, sumb) - cur;
answer = max(answer, cnt);
}
printf("%0.4f", answer);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |