#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define pb push_back
#define mp make_pair
#define f first
#define s second
void solve(){
int n;
cin >> n;
vector<double> a(n), b(n), prefix_b(n);
for(int i = 0; i < n; i++)
cin >> a[i] >> b[i];
sort(a.begin(), a.end(), greater<double>());
sort(b.begin(), b.end(), greater<double>());
prefix_b[0] = b[0];
for(int i = 1; i < n; i++)
prefix_b[i] = prefix_b[i-1] + b[i];
double total_a = 0, total_max = 0;
for(int i = 0; i < n; i++){
total_a += a[i];
auto it = upper_bound(prefix_b.begin(), prefix_b.end(), total_a) - prefix_b.begin();
if(it != n)
total_max = max(total_max, min(total_a - (i+it+2), prefix_b[it] - (i+it+2)));
it--;
if(it != -1)
total_max = max(total_max, min(total_a - (i+it+2), prefix_b[it] - (i+it+2)));
}
cout << fixed << setprecision(4) << total_max << '\n';
}
int main(){
//freopen("flota.in", "r", stdin);
//freopen("flota.out", "w", stdout);
ios::sync_with_stdio(0); cin.tie(0);
int t = 1;
//cin >> t;
while(t--){
solve();
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
600 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
600 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
1 ms |
344 KB |
Output is correct |
17 |
Correct |
64 ms |
2896 KB |
Output is correct |
18 |
Correct |
63 ms |
4168 KB |
Output is correct |
19 |
Correct |
63 ms |
3936 KB |
Output is correct |
20 |
Correct |
64 ms |
3924 KB |
Output is correct |
21 |
Correct |
66 ms |
4432 KB |
Output is correct |
22 |
Correct |
63 ms |
3944 KB |
Output is correct |
23 |
Correct |
64 ms |
3924 KB |
Output is correct |
24 |
Correct |
62 ms |
3936 KB |
Output is correct |
25 |
Correct |
62 ms |
4168 KB |
Output is correct |
26 |
Correct |
66 ms |
4332 KB |
Output is correct |