This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
//#define int long long
#define ll long long
#define ld long double
#define pb push_back
#define S second
#define F first
//const int inf = 1e18;
const int N = 100005;
int n, y;
long double a[N], b[N], pref[N], suma, ans;
ld f(int x){
// cout << x << ' ' << y << ' ' << pref[x] << ' ' << suma << '\n';
return min(pref[x], suma) - x - y;
}
main(){
// ios_base::sync_with_stdio(0);
// cin.tie(0);
// cout.tie(0);
cin >> n;
for(int i = 1; i <= n; ++i){
cin >> a[i] >> b[i];
}
sort(a + 1, a + 1 + n, greater<ld>());
sort(b + 1, b + 1 + n, greater<ld>());
for(int i = 0; i <= n; ++i){
pref[i] += pref[i - 1] + b[i];
}
for(int i = 0; i <= n; ++i){
// cout << a[i] << ' ';
suma += a[i];
y = i;
// for(int j = 0; j <= n; ++j){
// }
int l = 0, r = n;
// ld = eps = 1e-9
while(r - l > 2){
int m1 = l + (r - l) / 3, m2 = r - (r - l) / 3;
if(f(m1) < f(m2))
l = m1 + 1;
else
r = m2 - 1;
}
ans = max(ans, f(l));
if(l + 1 <= n)
ans = max(ans, f(l + 1));
if(l + 2 <= n)
ans = max(ans, f(l + 2));
}
cout << fixed << setprecision(4) << ans;
}
Compilation message (stderr)
sure.cpp:22:2: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
22 | main(){
| ^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |