// In the name of God
// Hope is last to die
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define pb push_back
// #define int long long
#define S second
#define F first
#define mp make_pair
#define smax(x, y) (x) = max((x), (y))
#define smin(x, y) (x) = min((x), (y))
#define all(x) (x).begin(), (x).end()
#define len(x) ((int)(x).size())
const int maxn = 1e5 + 5;
const int inf = 1e9 + 7;
int n;
double a[maxn], b[maxn], psa[maxn], psb[maxn];
int32_t main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n;
for(int i = 1; i <= n; i++) cin >> a[i] >> b[i];
sort(a + 1, a + n + 1);
sort(b + 1, b + n + 1);
reverse(a + 1, a + n + 1);
reverse(b + 1, b + n + 1);
for(int i = 1; i <= n; i++){
psa[i] = psa[i - 1] + a[i];
psb[i] = psb[i - 1] + b[i];
}
double ans = 0;
double mx = 0;
int cur = 0;
for(int i = 0; i <= n; i++){
while(cur <= n && psb[cur] <= psa[i]){
smax(mx, psb[cur] - cur);
cur++;
}
smax(ans, mx - i);
}
mx = 0;
cur = 0;
for(int i = 0; i <= n; i++){
while(cur <= n && psa[cur] <= psb[i]){
smax(mx, psa[cur] - cur);
cur++;
}
smax(ans, mx - i);
}
cout << setprecision(4) << fixed << ans << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2636 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2516 KB |
Output is correct |
6 |
Correct |
1 ms |
2656 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2636 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2516 KB |
Output is correct |
6 |
Correct |
1 ms |
2656 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2528 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2636 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2516 KB |
Output is correct |
6 |
Correct |
1 ms |
2656 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2528 KB |
Output is correct |
17 |
Correct |
61 ms |
4752 KB |
Output is correct |
18 |
Correct |
56 ms |
4756 KB |
Output is correct |
19 |
Correct |
55 ms |
4752 KB |
Output is correct |
20 |
Correct |
56 ms |
4692 KB |
Output is correct |
21 |
Correct |
59 ms |
5204 KB |
Output is correct |
22 |
Correct |
55 ms |
4752 KB |
Output is correct |
23 |
Correct |
55 ms |
4752 KB |
Output is correct |
24 |
Correct |
55 ms |
4688 KB |
Output is correct |
25 |
Correct |
55 ms |
4928 KB |
Output is correct |
26 |
Correct |
60 ms |
5200 KB |
Output is correct |