#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
#define INF 1000000000
#define LINF 1000000000000000LL
#define pb push_back
#define all(x) x.begin(), x.end()
#define len(s) (int)s.size()
#define test_case { int t; cin>>t; while(t--)solve(); }
#define single_case solve();
#define line cerr<<"----------"<<endl;
#define ios { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cerr.tie(NULL); }
#define mod 1000000007LL
const int N = 1e5 + 50;
double a[N], b[N];
double prefix[N];
int n;
int main()
{
ios
cin>>n;
for(int i = 1;i<=n;i++) cin>>a[i]>>b[i];
sort(a+1, a+n+1);
sort(b+1, b+n+1);
reverse(b+1, b+n+1);
reverse(a+1, a+n+1);
for(int i = 1;i<=n;i++) prefix[i] = prefix[i-1] + b[i];
prefix[n+1] = 1000000000.0;
double res = 0;
double sum = 0;
for(int i = 1;i<=n;i++)
{
sum += a[i];
int ind = lower_bound(prefix+1, prefix+n+2, sum) - (prefix);
if(ind<=n) res = max(res, sum-(double)i-(double)ind);
}
for(int i = 1;i<=n;i++) prefix[i] = prefix[i-1] + a[i];
sum = 0;
for(int i = 1;i<=n;i++)
{
sum += b[i];
int ind = lower_bound(prefix+1, prefix+n+2, sum) - (prefix);
if(ind<=n) res = max(res, sum-(double)i-(double)ind);
}
printf("%.4lf", res);
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
492 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
2 ms |
364 KB |
Output is correct |
13 |
Correct |
2 ms |
364 KB |
Output is correct |
14 |
Correct |
2 ms |
364 KB |
Output is correct |
15 |
Correct |
2 ms |
364 KB |
Output is correct |
16 |
Correct |
2 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
492 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
2 ms |
364 KB |
Output is correct |
13 |
Correct |
2 ms |
364 KB |
Output is correct |
14 |
Correct |
2 ms |
364 KB |
Output is correct |
15 |
Correct |
2 ms |
364 KB |
Output is correct |
16 |
Correct |
2 ms |
364 KB |
Output is correct |
17 |
Correct |
119 ms |
4076 KB |
Output is correct |
18 |
Correct |
107 ms |
4204 KB |
Output is correct |
19 |
Correct |
118 ms |
4076 KB |
Output is correct |
20 |
Correct |
99 ms |
4076 KB |
Output is correct |
21 |
Correct |
108 ms |
4460 KB |
Output is correct |
22 |
Correct |
124 ms |
4076 KB |
Output is correct |
23 |
Correct |
101 ms |
4076 KB |
Output is correct |
24 |
Correct |
100 ms |
4076 KB |
Output is correct |
25 |
Correct |
98 ms |
4076 KB |
Output is correct |
26 |
Correct |
105 ms |
4460 KB |
Output is correct |