#include <bits/stdc++.h>
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
#define optimus_prime ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define fxd(x) fixed << setprecision(x)
#define all(a) (a.begin() , a.end())
#define popcount(x) __builtin_popcount(x)
#define lwb lower_bound
#define upb upper_bound
#define dl long double
#define ll long long
#define pb push_back
#define sz() size()
#define F first
#define S second
using namespace std;
const ll N = 1e5+9;
const ll inf=1e9+9;
const ll mod=1e9+7;
const ll P = 37;
ll n;
dl a[N] , b[N] , ans;
void solve(){
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);
for (int i = 1 ; i <= 2*n ; i++){
dl sum1=0 , sum2=0;
ll ind1=1 , ind2=1 , cnt=i;
while (sum1<i&&cnt){
sum1+=a[ind1];
ind1++;
cnt--;
}
while (sum2<i&&cnt){
sum2+=(b[ind2]);
ind2++;
cnt--;
}
while (cnt){
cnt--;
if (ind1>n){
sum2+=b[ind2];
ind2++;
continue;
}
if (ind2>n){
sum1+=a[ind1];
ind1++;
continue;
}
if (sum1<sum2){
sum1+=a[ind1];
ind1++;
}
else {
sum2+=b[ind2];
ind2++;
}
}
sum1-=i;
sum2-=i;
ans=max(ans , min(sum1 , sum2));
}
cout << fxd(4) << ans;
}
signed main() {
optimus_prime;
solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2648 KB |
Output is correct |
3 |
Correct |
1 ms |
2648 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2392 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2648 KB |
Output is correct |
3 |
Correct |
1 ms |
2648 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2392 KB |
Output is correct |
7 |
Correct |
1 ms |
2516 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2392 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
5 ms |
2396 KB |
Output is correct |
13 |
Correct |
6 ms |
2396 KB |
Output is correct |
14 |
Correct |
5 ms |
2396 KB |
Output is correct |
15 |
Correct |
5 ms |
2532 KB |
Output is correct |
16 |
Correct |
5 ms |
2396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2648 KB |
Output is correct |
3 |
Correct |
1 ms |
2648 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2392 KB |
Output is correct |
7 |
Correct |
1 ms |
2516 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2392 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
5 ms |
2396 KB |
Output is correct |
13 |
Correct |
6 ms |
2396 KB |
Output is correct |
14 |
Correct |
5 ms |
2396 KB |
Output is correct |
15 |
Correct |
5 ms |
2532 KB |
Output is correct |
16 |
Correct |
5 ms |
2396 KB |
Output is correct |
17 |
Execution timed out |
2021 ms |
4740 KB |
Time limit exceeded |
18 |
Halted |
0 ms |
0 KB |
- |