///In the name of GOD
//#pragma GCC optimize("O2")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MXN = 3e5 + 10;
const ld EPS = 1e-9;
ll n;
ld A[MXN], B[MXN], psa[MXN], psb[MXN], ans;
ld Cal(ll x, ll y){
return min(psa[x], psb[y]) - x - y;
}
ld Calc(){
for(int i = 1; i <= n; i ++){
psa[i] = psa[i - 1] + A[i];
psb[i] = psb[i - 1] + B[i];
}
for(int i = 1; i <= n; i ++){
ll l = 0, r = n;
ans = max(ans, Cal(i, l));
ans = max(ans, Cal(i, r));
while(r - l > 10){
ll tid1 = (l * 2 + r) / 3;
ll tid2 = (l + r * 2) / 3;
ld nw1 = Cal(i, tid1);
ld nw2 = Cal(i, tid2);
ans = max(ans, nw1);
ans = max(ans, nw2);
if(nw1 > nw2) r = tid2;
else l = tid1;
}
for(int j = l; j <= r; j ++){
ans = max(ans, Cal(i, j));
}
}
return ans;
}
int main(){
ios::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, greater<ld>());
sort(B + 1, B + n + 1, greater<ld>());
ans = max(ans, Calc());
swap(A, B);
ans = max(ans, Calc());
cout << fixed << setprecision(4) << ans << '\n';
return 0;
}
/*!
HE'S AN INSTIGATOR,
ENEMY ELIMINATOR,
AND WHEN HE KNOCKS YOU BETTER
YOU BETTER LET HIM IN.
*/
//! N.N
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
9676 KB |
Output is correct |
2 |
Correct |
8 ms |
9676 KB |
Output is correct |
3 |
Correct |
8 ms |
9644 KB |
Output is correct |
4 |
Correct |
9 ms |
9728 KB |
Output is correct |
5 |
Correct |
8 ms |
9676 KB |
Output is correct |
6 |
Correct |
8 ms |
9676 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
9676 KB |
Output is correct |
2 |
Correct |
8 ms |
9676 KB |
Output is correct |
3 |
Correct |
8 ms |
9644 KB |
Output is correct |
4 |
Correct |
9 ms |
9728 KB |
Output is correct |
5 |
Correct |
8 ms |
9676 KB |
Output is correct |
6 |
Correct |
8 ms |
9676 KB |
Output is correct |
7 |
Correct |
9 ms |
9676 KB |
Output is correct |
8 |
Correct |
9 ms |
9664 KB |
Output is correct |
9 |
Correct |
10 ms |
9676 KB |
Output is correct |
10 |
Correct |
11 ms |
9676 KB |
Output is correct |
11 |
Correct |
11 ms |
9676 KB |
Output is correct |
12 |
Correct |
10 ms |
9708 KB |
Output is correct |
13 |
Correct |
11 ms |
9676 KB |
Output is correct |
14 |
Correct |
10 ms |
9672 KB |
Output is correct |
15 |
Correct |
11 ms |
9676 KB |
Output is correct |
16 |
Correct |
10 ms |
9676 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
9676 KB |
Output is correct |
2 |
Correct |
8 ms |
9676 KB |
Output is correct |
3 |
Correct |
8 ms |
9644 KB |
Output is correct |
4 |
Correct |
9 ms |
9728 KB |
Output is correct |
5 |
Correct |
8 ms |
9676 KB |
Output is correct |
6 |
Correct |
8 ms |
9676 KB |
Output is correct |
7 |
Correct |
9 ms |
9676 KB |
Output is correct |
8 |
Correct |
9 ms |
9664 KB |
Output is correct |
9 |
Correct |
10 ms |
9676 KB |
Output is correct |
10 |
Correct |
11 ms |
9676 KB |
Output is correct |
11 |
Correct |
11 ms |
9676 KB |
Output is correct |
12 |
Correct |
10 ms |
9708 KB |
Output is correct |
13 |
Correct |
11 ms |
9676 KB |
Output is correct |
14 |
Correct |
10 ms |
9672 KB |
Output is correct |
15 |
Correct |
11 ms |
9676 KB |
Output is correct |
16 |
Correct |
10 ms |
9676 KB |
Output is correct |
17 |
Correct |
219 ms |
14124 KB |
Output is correct |
18 |
Correct |
207 ms |
14172 KB |
Output is correct |
19 |
Correct |
216 ms |
14212 KB |
Output is correct |
20 |
Correct |
209 ms |
14168 KB |
Output is correct |
21 |
Correct |
215 ms |
14476 KB |
Output is correct |
22 |
Correct |
209 ms |
14208 KB |
Output is correct |
23 |
Correct |
209 ms |
14152 KB |
Output is correct |
24 |
Correct |
214 ms |
14228 KB |
Output is correct |
25 |
Correct |
216 ms |
14200 KB |
Output is correct |
26 |
Correct |
219 ms |
14576 KB |
Output is correct |