#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("avx2,fma")
#define rep(i,l,r) for (int i = l; i < r; i++)
#define repr(i,r,l) for (int i = r; i >= l; i--)
#define X first
#define Y second
#define pb push_back
#define endl '\n'
#define debug(x) cerr << #x << " : " << x << endl;
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pll;
const long long int N = 1e5+20,mod = 1e9+7,inf = 1e9+10,sq = 400;
inline int mkay(int a,int b){
if (a+b >= mod) return a+b-mod;
if (a+b < 0) return a+b+mod;
return a+b;
}
inline int poww(int n,int k){
int c = 1;
while (k){
if (k&1) c = (1ll*c*n)%mod;
n = (1ll*n*n)%mod;
k >>= 1;
}
return c;
}
ld a[N],b[N];
ld suf[N][2];
int n;
inline ld check(int i){
if (i > n || i < 0) return 0;
ld ans = min(suf[n-i][0]-i,ld(0));
rep(j,1,n+1){
ans = max(ans,min(suf[n-i][0],suf[n-j][1])-i-j);
}
return ans;
}
inline ld ternery(){
int l = 0,r = n,m1 = 9,m2 = 0;
while (r-l > 2){
m1 = (2*l+r)/3;
m2 = (l+2*r)/3;
if (check(m1) < check(m2)) l = m1;
else r = m2;
}
ld ans = max(check(0),check(n));
rep(i,-300,300) ans = max(check(l+i),ans);
return ans;
}
int main(){
ios :: sync_with_stdio(0); cin.tie(0);
cin >> n;
rep(i,0,n){
cin >> a[i] >> b[i];
}
sort(a,a+n);
sort(b,b+n);
repr(i,n-1,0){
suf[i][0] = suf[i+1][0]+a[i];
suf[i][1] = suf[i+1][1]+b[i];
}
cout << setprecision(4) << fixed << max(ld(0),ternery()) << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
320 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
300 KB |
Output is correct |
5 |
Correct |
0 ms |
308 KB |
Output is correct |
6 |
Correct |
0 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
320 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
300 KB |
Output is correct |
5 |
Correct |
0 ms |
308 KB |
Output is correct |
6 |
Correct |
0 ms |
332 KB |
Output is correct |
7 |
Correct |
0 ms |
324 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
312 KB |
Output is correct |
10 |
Correct |
0 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
3 ms |
336 KB |
Output is correct |
13 |
Correct |
3 ms |
332 KB |
Output is correct |
14 |
Correct |
3 ms |
332 KB |
Output is correct |
15 |
Correct |
4 ms |
336 KB |
Output is correct |
16 |
Correct |
3 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
320 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
300 KB |
Output is correct |
5 |
Correct |
0 ms |
308 KB |
Output is correct |
6 |
Correct |
0 ms |
332 KB |
Output is correct |
7 |
Correct |
0 ms |
324 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
312 KB |
Output is correct |
10 |
Correct |
0 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
3 ms |
336 KB |
Output is correct |
13 |
Correct |
3 ms |
332 KB |
Output is correct |
14 |
Correct |
3 ms |
332 KB |
Output is correct |
15 |
Correct |
4 ms |
336 KB |
Output is correct |
16 |
Correct |
3 ms |
332 KB |
Output is correct |
17 |
Correct |
331 ms |
7876 KB |
Output is correct |
18 |
Correct |
358 ms |
7876 KB |
Output is correct |
19 |
Correct |
338 ms |
7936 KB |
Output is correct |
20 |
Correct |
341 ms |
8004 KB |
Output is correct |
21 |
Correct |
345 ms |
8308 KB |
Output is correct |
22 |
Correct |
334 ms |
7876 KB |
Output is correct |
23 |
Correct |
333 ms |
8004 KB |
Output is correct |
24 |
Correct |
336 ms |
7988 KB |
Output is correct |
25 |
Correct |
330 ms |
7932 KB |
Output is correct |
26 |
Correct |
339 ms |
8308 KB |
Output is correct |