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 all(x) x.begin(), x.end()
#define ar array
#define pb push_back
#define ln '\n'
#define int long long
using i64 = long long;
template <class F, class _S>
bool chmin(F &u, const _S &v){
bool flag = false;
if ( u > v ){
u = v; flag |= true;
}
return flag;
}
template <class F, class _S>
bool chmax(F &u, const _S &v){
bool flag = false;
if ( u < v ){
u = v; flag |= true;
}
return flag;
}
#define double long double
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n; cin >> n;
vector <double> a(n), b(n);
for ( int i = 0; i < n; i++ ){
cin >> a[i] >> b[i];
}
sort(all(a), greater <double> ());
sort(all(b), greater <double> ());
b.pb(0), a.pb(0);
vector <double> pf(n + 1);
for ( int i = 0; i < n; i++ ){
pf[i + 1] = pf[i] + b[i];
}
auto get = [&](int l, int r){
return pf[r + 1] - pf[l];
};
int j = 0;
double opt = 0, cnt = 0, mx = 0;
for ( int i = 0; i <= n; i++ ){
while ( j < n && pf[j] <= cnt ){
chmax(mx, pf[j] - j);
j++;
}
chmax(opt, mx - i);
if ( j < n ){
chmax(opt, cnt - (i + j));
}
cnt += a[i];
}
cout << fixed << setprecision(4) << opt;
cout << '\n';
}
Compilation message (stderr)
sure.cpp: In function 'int main()':
sure.cpp:49:10: warning: variable 'get' set but not used [-Wunused-but-set-variable]
49 | auto get = [&](int l, int r){
| ^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |