#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
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
320 KB |
Output is correct |
5 |
Correct |
1 ms |
320 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
320 KB |
Output is correct |
5 |
Correct |
1 ms |
320 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
2 ms |
332 KB |
Output is correct |
13 |
Correct |
2 ms |
332 KB |
Output is correct |
14 |
Correct |
2 ms |
332 KB |
Output is correct |
15 |
Correct |
2 ms |
332 KB |
Output is correct |
16 |
Correct |
2 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
320 KB |
Output is correct |
5 |
Correct |
1 ms |
320 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
2 ms |
332 KB |
Output is correct |
13 |
Correct |
2 ms |
332 KB |
Output is correct |
14 |
Correct |
2 ms |
332 KB |
Output is correct |
15 |
Correct |
2 ms |
332 KB |
Output is correct |
16 |
Correct |
2 ms |
332 KB |
Output is correct |
17 |
Correct |
124 ms |
7908 KB |
Output is correct |
18 |
Correct |
128 ms |
7900 KB |
Output is correct |
19 |
Correct |
127 ms |
7940 KB |
Output is correct |
20 |
Correct |
120 ms |
8004 KB |
Output is correct |
21 |
Correct |
134 ms |
8260 KB |
Output is correct |
22 |
Correct |
125 ms |
7868 KB |
Output is correct |
23 |
Correct |
128 ms |
7876 KB |
Output is correct |
24 |
Correct |
128 ms |
7832 KB |
Output is correct |
25 |
Correct |
120 ms |
7864 KB |
Output is correct |
26 |
Correct |
132 ms |
8260 KB |
Output is correct |