#include<bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define pb push_back
#define ii pair<int, int>
#define sz(v) (int)v.size()
#define all(v) v.begin(), v.end()
using namespace std;
const int N=1e5+5, mod = 1e9+7, inf = 1e18;
int n;
double a[N], b[N];
signed 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]; a[i]-=1.0; b[i]-=1.0;
}
sort(a+1, a+n+1, greater<double>()); sort(b+1, b+n+1, greater<double>());
for (int i=1; i<=n; i++) {
a[i] += a[i-1]; b[i] += b[i-1];
}
double res = (double) -inf;
for (int na = 0; na<=n; na++) {
int lo = 0, hi = n, ans = -1;
while(lo<=hi) {
int mid = (lo+hi)>>1;
if(a[na] - mid >= b[mid] - na) {
ans = mid;
lo = mid+1;
} else {
hi = mid-1;
}
}
if(ans != -1) res = max(res, b[ans]-na);
if(ans<n) res = max(res, a[na]-ans-1);
}
cout << fixed << setprecision(4) << res;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
604 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
604 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
376 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
604 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
376 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
45 ms |
1876 KB |
Output is correct |
18 |
Correct |
46 ms |
1996 KB |
Output is correct |
19 |
Correct |
47 ms |
1860 KB |
Output is correct |
20 |
Correct |
47 ms |
1884 KB |
Output is correct |
21 |
Correct |
47 ms |
1876 KB |
Output is correct |
22 |
Correct |
53 ms |
1876 KB |
Output is correct |
23 |
Correct |
47 ms |
1872 KB |
Output is correct |
24 |
Correct |
48 ms |
1784 KB |
Output is correct |
25 |
Correct |
51 ms |
1884 KB |
Output is correct |
26 |
Correct |
48 ms |
1884 KB |
Output is correct |