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;
#define FOR(i, a, b) for(int i = a; i < b; ++i)
#define REP(i, n) FOR(i, 0, n)
#define _ << " " <<
#define sz(x) ((int) x.size())
#define pb(x) push_back(x)
#define TRACE(x) cerr << #x << " = " << x << endl
typedef long long ll;
typedef pair<int, int> point;
const int MAXN = 1e5 + 5;
int n;
double a[MAXN], b[MAXN];
int main(){
ios_base::sync_with_stdio(false); cin.tie(0);
cin >> n;
REP(i, n){
cin >> a[i] >> b[i];
}
sort(a, a + n, greater<double>());
sort(b, b + n, greater<double>());
double sol = 0;
double lt = 0, rt = 0;
int pnt = 0, total = 0;
REP(i, n){
lt += a[i];
total ++;
while(pnt < n && lt > rt){
rt += b[pnt];
pnt ++;
total ++;
sol = max(sol, min(lt, rt) - total);
}
sol = max(sol, min(lt, rt) - total);
}
lt = rt = pnt = total = 0;
REP(i, n){
rt += b[i];
total ++;
while(pnt < n && rt > lt){
lt += a[pnt];
total ++;
pnt ++;
sol = max(sol, min(lt, rt) - total);
}
sol = max(sol, min(lt, rt) - total);
}
cout << setprecision(4) << fixed << sol;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |