///* __ __ __ */
///* ====== _ /| /| __ _ / | | /| | @ | | | | / /| |\ | / | | @ | / */
///* \- || |_| |_ / |/ | | | |_ |- | |--| /-| | | \ \ |==| |- /=| | \ | | |--| | |- */
///* || | | |_ / | |__| _| |_ \__ | | / | |__ | __| | | | \ / | | \| \__ | | | | \ */
///*
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ff first
#define ss second
#define int long long
typedef vector<int> vi;
typedef vector<double> vd;
typedef pair<int,int> pii;
typedef vector<pii> vii;
const int N = 3e5+50, inf = 1e18, mod = 1e9+7;
void solve(){
int n;
cin >> n;
vd a(n+2, 0), b(n+2, 0);
for(int i = 0; i < n; i++)cin >> a[i] >> b[i];
sort(a.rbegin(), a.rend());
sort(b.rbegin(), b.rend());
double ans = 0;
vd pr;pr.pb(0);
for(auto i:b)pr.pb(pr.back()+i);
double sma = 0, cnt = 0;
for(int i = 0; i < n; i++){
sma+=a[i];
cnt++;
int l = 0, r = n;
while(l <= r){
int m = (l+r)>>1;
if(sma - (cnt+m) < pr[m] - (cnt+m)){
r = m-1;
}else{
l = m+1;
}
ans = max(ans, min(sma-(cnt+m) , pr[m] - (cnt+m)));
}
//cout << '\n';
}
cout << fixed << setprecision(4);
cout << ans << '\n';
}
main(){
//ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int test = 1;
//cin >> test;
while(test--){
solve();
}
}
Compilation message
sure.cpp:50:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
50 | main(){
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 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 |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 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 |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
2 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 |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 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 |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
2 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 |
101 ms |
3128 KB |
Output is correct |
18 |
Correct |
101 ms |
3020 KB |
Output is correct |
19 |
Correct |
101 ms |
3016 KB |
Output is correct |
20 |
Correct |
101 ms |
3136 KB |
Output is correct |
21 |
Correct |
111 ms |
3128 KB |
Output is correct |
22 |
Correct |
101 ms |
3148 KB |
Output is correct |
23 |
Correct |
101 ms |
3016 KB |
Output is correct |
24 |
Correct |
102 ms |
3128 KB |
Output is correct |
25 |
Correct |
100 ms |
3144 KB |
Output is correct |
26 |
Correct |
110 ms |
3020 KB |
Output is correct |