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;
typedef long long ll;
typedef long double ld;
#define S second
#define F first
#define pb push_back
#define mp make_pair
#define pii pair <int, int>
#define fast_io ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const int maxn = 1e5 + 5;
ld a[maxn], b[maxn], ps1[maxn], ps2[maxn];
int main(){
fast_io;
int n;
cin >> n;
for(int i = 0; i < n; i ++){
cin >> a[i] >> b[i];
}
sort(a, a + n, greater <ld>());
sort(b, b + n, greater <ld>());
ps1[0] = a[0]; ps2[0] = b[0];
for(int i = 1; i < n; i ++){
ps1[i] = ps1[i - 1] + a[i];
ps2[i] = ps2[i - 1] + b[i];
//cout << ps1[i] << " " << ps2[i] << endl;
}
ld ans = 0;
for(int i = 0; i < n; i ++){
int x = lower_bound(ps2, ps2 + n, ps1[i]) - ps2;
if(x == n){
continue;
}
ans = max(ans, ps1[i] - (i + x + 2));
}
for(int i = 0; i < n; i ++){
int x = lower_bound(ps1, ps1 + n, ps2[i]) - ps1;
if(x == n){
continue;
}
ans = max(ans, ps2[i] - (i + x + 2));
}
cout << setprecision(4) << fixed << ans;
return 0;
}
/*
4
1.4 3.7
1.2 2
1.6 1.4
1.9 1.5
*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |