이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |