#include<bits/stdc++.h>
// #pragma GCC optimize("03,unroll-loops")
// #pragma GCC target("avx2,fma,bmi2,lzcnt,popcnt")
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC target("avx,avx2,fma")
#define endl "\n"
#define pb push_back
#define rs resize
using namespace std;
void solve() {
int n; cin >> n;
double a[n], b[n];
for (int i = 0; i < n; ++i) {
cin >> a[i] >> b[i];
a[i]--, b[i]--;
}
sort(a, a + n), reverse(a, a + n);
sort(b, b + n); reverse(b, b + n);
int j = 0, i = 0;
long double sum_a = 0, sum_b = 0, res = 0;
while (i < n) {
sum_a += a[i];
i++;
while (j < n && min(sum_a - j, sum_b - i) < min(sum_a - (j + 1), (sum_b + b[j]) - i)) {
sum_b += b[j];
j++;
}
res = max(res, min(sum_a - j, sum_b - i));
}
cout << fixed << setprecision(4) << res;
}
// le pham gia hung thich bu cu
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
// int t; cin >> t;
// while (t--)
solve();
return 0;
}
/*
#define hung_lon long long
#define le_pham_gia_hung_aka_le_phot_ra_tinh int
#define anh_hung_bu_cu cin
#define anh_hung_thoi_bu_cu cout
#define le_pham_gia_hung_thich_bu_cu string
#define le_pham_gia_hung_phot_ra_tinh char
#define le_pham_gia_hung_bu_cu_suot_ngay long double
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 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 |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 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 |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 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 |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
47 ms |
2020 KB |
Output is correct |
18 |
Correct |
49 ms |
1880 KB |
Output is correct |
19 |
Correct |
49 ms |
1884 KB |
Output is correct |
20 |
Correct |
48 ms |
1884 KB |
Output is correct |
21 |
Correct |
52 ms |
1884 KB |
Output is correct |
22 |
Correct |
48 ms |
1880 KB |
Output is correct |
23 |
Correct |
49 ms |
1884 KB |
Output is correct |
24 |
Correct |
49 ms |
1880 KB |
Output is correct |
25 |
Correct |
48 ms |
1880 KB |
Output is correct |
26 |
Correct |
52 ms |
1880 KB |
Output is correct |