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;
const long long inf = (long long) 1e18 + 10;
const int inf1 = (int) 1e9 + 10;
#define int long long
#define dbl long double
#define endl '\n'
#define sc second
#define fr first
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()
#define maxn
void solve() {
int n;
cin >> n;
vector<dbl> a,b;
for(int i = 1; i <= n; i++) {
dbl a1, b1;
cin >> a1 >> b1;
a.pb(a1);
b.pb(b1);
}
sort(all(a),greater<dbl>());
sort(all(b),greater<dbl>());
int pa = 0;
dbl sa = 0;
int pb = 0;
dbl sb = 0;
dbl ans = 0;
while(pa != n || pb != n) {
if(pa == n) {
sb+= b[pb];
pb++;
}
else if(pb == n) {
sa+= a[pa];
pa++;
}
else if(sa < sb) {
sa+= a[pa];
pa++;
}
else {
sb+= b[pb];
pb++;
}
ans = max(ans, min(sa - (pa+pb), sb - (pa+pb)));
}
cout.setf(ios::fixed);
cout.precision(4);
cout << ans << endl;
}
int32_t main() {
ios::sync_with_stdio(false); cin.tie(0);
// freopen("in.in", "r", stdin);
//freopen("out.out", "w", stdout);
int tt = 1;
// cin >> tt;
while(tt--) solve();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |