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 rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<ll>
#define vvi vector<vi>
#define pp pair<ll,ll>
#define vp vector<pp>
#define vvp vector<vp>
#define inf 1000000000000000000
#define mod 1000000007
using namespace std;
int main() {
cin.tie(NULL);
ios_base::sync_with_stdio(false);
int n;
cin >> n;
vector<double> A(n), B(n);
rep(i,n){
cin >> A[i] >> B[i];
}
sort(A.begin(), A.end());
sort(B.begin(), B.end());
int pocet = 0;
double a = 0, b = 0;
int ia = n - 1;
int ib = n-1;
double ans = 0;
while(true){
if(a > b){
if(ib < 0) break;
pocet++;
b += B[ib];
ib--;
}else{
if(ia < 0) break;
pocet++;
a += A[ia];
ia--;
}
ans = max(ans, min(a - pocet, b - pocet));
}
printf("%.4lf",(double)ans);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |