#include <iostream>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <vector>
#include <string>
#include <sstream>
#include <cstring>
// #pragma GCC optimize("inline")
// #pragma GCC optimize("-fgcse,-fgcse-lm")
// #pragma GCC optimize("-ftree-pre,-ftree-vrp")
// #pragma GCC optimize("-ffast-math")
// #pragma GCC optimize("-fipa-sra")
// #pragma GCC optimize("-fpeephole2")
// #pragma GCC optimize("-fsched-spec")
// #pragma GCC optimize("Ofast,no-stack-protector")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
// #pragma GCC optimize("unroll-loops")
#define ll long long int
#define pb push_back
#define pll pair < ll , ll >
#define fi first
#define se second
#define all(x) x.begin(), x.end()
using namespace std;
ll inf2 = 3e18;
double a[ 100111 ], b[ 100111 ], sum1, sum2, cnt, grnt, agrnt;
pair < double , double > c[ 100111 ];
vector < pll > unused, overused;
int main(){
ll n;
cin >> n;
for(int i = 1; i <= n; i ++){
cin >> a[ i ] >> b[ i ];
// c[ i ].fi = a[ i ];
// c[ i ].se = b[ i ];
}
if(n == 1){
cout << a[ 1 ] + b[ 1 ] - 2;
return 0;
}
sort(a + 1, a + 1 + n);
sort(b + 1, b + 1 + n);
sum1 = a[ n ];
sum2 = b[ n ];
cnt = 2.0;
grnt = min(sum1 - cnt, sum2 - cnt);
for(int i = n - 1; i >= 1; i --){
double sit1a, sit1b, sit2a, sit2b, sit3a, sit3b, grnt1, grnt2, grnt3;
sit1a = sum1 + a[ i ] - (cnt + 1);
sit1b = sum2 - (cnt + 1);
grnt1 = min(sit1a, sit1b);
sit2a = sum1 - (cnt + 1);
sit2b = sum2 + b[ i ] - (cnt + 1);
grnt2 = min(sit2a, sit2b);
sit3a = sum1 + a[ i ] - (cnt + 2);
sit3b = sum2 + b[ i ] - (cnt + 2);
grnt3 = min(sit3a, sit3b);
if(grnt1 >= grnt2 && grnt1 >= grnt3 && grnt1 > grnt){
sum1 += a[ i ];
cnt ++;
grnt = grnt1;
}else if(grnt2 >= grnt1 && grnt2 >= grnt3 && grnt2 > grnt){
sum2 += b[ i ];
cnt ++;
grnt = grnt2;
}else if(grnt3 > grnt2 && grnt3 > grnt1 && grnt3 > grnt){
sum1 += a[ i ];
sum2 += b[ i ];
cnt += 2;
grnt = grnt3;
}
}
if(a[ n ] > 2.0 && b[ n ] > 2.0){
agrnt = min(a[ n ] - 2, b[ n ] - 2);
for(int i = n - 1; i >= 1; i --){
if(a[ i ] > 2.0 && b[ i ] > 2.0){
agrnt += min(a[ i ] - 2, b[ i ] - 2);
}
}
}
printf("%.4lf", max(0.0, max(agrnt, grnt)));
}
/*
4
1.4 3.7
1.2 2
1.6 1.4
1.9 1.5
10
1 2
3 4
4 7
9 3
5 4
1.5 5.6
4.3 4.5
9.8 3.4
3.2 4.3
5.6 7.3
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |