#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define ld long double
const int maxn = 1e5 + 20;
ld res , sum[maxn] , a[maxn] , b[maxn];
void solve(int n)
{
sort(a + 1 , a + n + 1);
sort(b + 1 , b + n + 1);
reverse(a + 1 , a + n + 1);
reverse(b + 1 , b + n + 1);
for(int i = 1; i <= n; i++)
sum[i] = sum[i - 1] + b[i];
ld s = 0;
for(int i = 1; i <= n; i++)
{
s += a[i];
int k = lower_bound(sum , sum + n + 1 , s) - sum;
if(k > n + 1)
k--;
res = max(res , min(sum[k] , s) - k - i);
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
for(int i = 1; i <= n; i++)
cin >> a[i] >> b[i];
solve(n);
for(int i = 1; i <= n; i++)
swap(a[i] , b[i]);
solve(n);
cout << fixed << setprecision(4) << res << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
8 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Correct |
3 ms |
384 KB |
Output is correct |
13 |
Correct |
3 ms |
384 KB |
Output is correct |
14 |
Correct |
3 ms |
384 KB |
Output is correct |
15 |
Correct |
3 ms |
384 KB |
Output is correct |
16 |
Correct |
3 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
8 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Correct |
3 ms |
384 KB |
Output is correct |
13 |
Correct |
3 ms |
384 KB |
Output is correct |
14 |
Correct |
3 ms |
384 KB |
Output is correct |
15 |
Correct |
3 ms |
384 KB |
Output is correct |
16 |
Correct |
3 ms |
384 KB |
Output is correct |
17 |
Correct |
119 ms |
6432 KB |
Output is correct |
18 |
Correct |
117 ms |
6344 KB |
Output is correct |
19 |
Correct |
117 ms |
6336 KB |
Output is correct |
20 |
Correct |
119 ms |
6352 KB |
Output is correct |
21 |
Correct |
127 ms |
6780 KB |
Output is correct |
22 |
Correct |
123 ms |
6492 KB |
Output is correct |
23 |
Correct |
122 ms |
6424 KB |
Output is correct |
24 |
Correct |
121 ms |
6444 KB |
Output is correct |
25 |
Correct |
118 ms |
6452 KB |
Output is correct |
26 |
Correct |
126 ms |
6748 KB |
Output is correct |