//gm --- akezhon
#include <bits/stdc++.h>
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define int long long
#define pb push_back
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define pii pair<int,int>
#define tm (tl+tr)/2
#define TL v+v, tl, tm
#define TR v+v+1, tm+1, tr
#define DA l <= tl && tr <= r
#define NET r < tl || tr < l
#define double long double
using namespace std;
const int N=1e5+7;
const int M=1e9+7;
const int inf=1e9;
double a[N], b[N];
int n;
void AlemAmenov(){
cin >> n;
for(int i=1; i <= n; i++){
cin >> a[i] >> b[i];
}
sort(a+1, a+1+n);
sort(b+1, b+1+n);
reverse(a+1, a+1+n);
reverse(b+1, b+1+n);
int c1=n, c2=n;
double aa=0, bb=0;
for(int i=1; i <= n; i++){
aa += a[i];
bb += b[i];
}
double ans = min(aa, bb) - c1 - c2;
while(1){
if(c1 && ans <= min(aa-a[c1], bb) - c1 - c2 + 1){
ans = min(aa-a[c1], bb) - c1 - c2 + 1;
aa -= a[c1--];
}
else if(c2 && ans <= min(aa, bb-b[c2]) - c1 - c2 + 1){
ans = min(aa, bb-b[c2]) - c1 - c2 + 1;
bb -= b[c2--];
}
else if(c1 && c2 && ans <= min(aa-a[c1], bb-b[c2]) - c1 - c2 + 2){
ans = min(aa-a[c1], bb-b[c2]) - c1 - c2 + 2;
aa -= a[c1--];
bb -= b[c2--];
}
else if(c1 && 1 < c2 && ans <= min(aa-a[c1], bb-b[c2]-b[c2-1]) - c1 - c2 + 3){
ans = min(aa-a[c1], bb-b[c2]-b[c2-1]) - c1 - c2 + 3;
aa -= a[c1--];
bb -= b[c2--];
bb -= b[c2--];
}
else if(1 < c1 && c2 && ans <= min(aa-a[c1]-a[c1-1], bb-b[c2]) - c1 - c2 + 3){
ans = min(aa-a[c1], bb-b[c2]-b[c2-1]) - c1 - c2 + 3;
aa -= a[c1--];
aa -= a[c1--];
bb -= b[c2--];
}
else break;
}
cout << fixed << setprecision(4) << ans;
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
// freopen("promote.in", "r", stdin);
// freopen("promote.out", "w", stdout);
int RealName=1;
// cin >> RealName;
// int C=0;
while(RealName--){
// cout << "Case " << ++C << ":\n";
AlemAmenov();
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
2648 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
2652 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
2396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
59 ms |
3412 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
48 ms |
3356 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |