#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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
3 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
3 ms |
376 KB |
Output is correct |
12 |
Correct |
3 ms |
376 KB |
Output is correct |
13 |
Correct |
3 ms |
376 KB |
Output is correct |
14 |
Correct |
3 ms |
376 KB |
Output is correct |
15 |
Correct |
3 ms |
376 KB |
Output is correct |
16 |
Correct |
3 ms |
432 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
3 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
3 ms |
376 KB |
Output is correct |
12 |
Correct |
3 ms |
376 KB |
Output is correct |
13 |
Correct |
3 ms |
376 KB |
Output is correct |
14 |
Correct |
3 ms |
376 KB |
Output is correct |
15 |
Correct |
3 ms |
376 KB |
Output is correct |
16 |
Correct |
3 ms |
432 KB |
Output is correct |
17 |
Correct |
97 ms |
3292 KB |
Output is correct |
18 |
Correct |
98 ms |
3268 KB |
Output is correct |
19 |
Correct |
99 ms |
3228 KB |
Output is correct |
20 |
Correct |
97 ms |
3320 KB |
Output is correct |
21 |
Correct |
105 ms |
3740 KB |
Output is correct |
22 |
Correct |
98 ms |
3352 KB |
Output is correct |
23 |
Correct |
96 ms |
3320 KB |
Output is correct |
24 |
Correct |
97 ms |
3320 KB |
Output is correct |
25 |
Correct |
102 ms |
3192 KB |
Output is correct |
26 |
Correct |
104 ms |
3704 KB |
Output is correct |