#include <bits/stdc++.h>
#define pb push_back
#define all(v) v.begin(),v.end()
#define ff first
#define ss second
using namespace std;
typedef long long ll;
typedef pair<long long, long long> pll;
typedef pair < int, int > pii;
typedef vector<int> vi;
typedef vector<long long> vll;
const int N = 2e5 + 123;
const ll mod = 1e9 + 7;
void solve(){
int n, cnt = 0;
cin >> n;
double a[n], b[n], out = 0, s = 0;
for(int i = 0; i < n; i++) {
cin >> a[i] >> b[i];
}
sort(a, a + n), sort(b, b + n);
for(int i = n - 2; i >= 0; i--) b[i] += b[i + 1];
for(int i = n - 1; i >= 0; i--) {
s += a[i] - 1;
int p = s;
cnt++;
int l = max(n - 1 - p, -1), r = n;
while(l + 1 < r) {
int mi = l + (r - l) / 2;
if(b[mi] - cnt <= s)r = mi;
else l = mi;
}
if(r != n)out = max(out, b[r] - cnt - (n - r));
if(r)out = max(out, s - (n - r) - 1);
}
cout << fixed << setprecision(4) << out;
}
int main() {
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
ios_base::sync_with_stdio(false);
cin.tie(0);
int times = 1;
//cin >> times;
while(times--)solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
308 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
308 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
312 KB |
Output is correct |
9 |
Correct |
1 ms |
312 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
2 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
324 KB |
Output is correct |
16 |
Correct |
1 ms |
328 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
308 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
312 KB |
Output is correct |
9 |
Correct |
1 ms |
312 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
2 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
324 KB |
Output is correct |
16 |
Correct |
1 ms |
328 KB |
Output is correct |
17 |
Correct |
72 ms |
2896 KB |
Output is correct |
18 |
Correct |
83 ms |
2852 KB |
Output is correct |
19 |
Correct |
79 ms |
2940 KB |
Output is correct |
20 |
Correct |
73 ms |
2856 KB |
Output is correct |
21 |
Correct |
83 ms |
2996 KB |
Output is correct |
22 |
Correct |
72 ms |
2888 KB |
Output is correct |
23 |
Correct |
71 ms |
2932 KB |
Output is correct |
24 |
Correct |
83 ms |
2860 KB |
Output is correct |
25 |
Correct |
92 ms |
2844 KB |
Output is correct |
26 |
Correct |
82 ms |
3012 KB |
Output is correct |