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
signed main(){
double n; cin >> n;
vector<double> a(n + 1), b(n + 1), pref(n + 1), prefb(n + 1);
a[0] = 1e9;
b[0] = 1e9;
for (int i = 1; i <= n; i++){
cin >> a[i];
cin >> b[i];
}
sort(a.begin(), a.end());
sort(b.begin(), b.end());
reverse(a.begin(), a.end());
reverse(b.begin(), b.end());
a[0] = 0;
b[0] = 0;
for (int i = 1; i <= n; i++){
pref[i] = pref[i - 1] + a[i];
prefb[i] = prefb[i - 1] + b[i];
}
double ans = 0;
int i = 0, j = 0;
for (double monedas = 1; monedas <= 2 * n; monedas++){
//cout << i << ' ' << j << endl;
if (i == n && j == n) break;
if (i == n){
ans = max(ans, min(pref[i] - monedas, prefb[j + 1] - monedas));
j++;
}else if (j == n){
ans = max(ans, min(pref[i + 1] - monedas, prefb[j] - monedas));
i++;
}else{
if (min(pref[i + 1] - monedas, prefb[j] - monedas) >= min(pref[i] - monedas, prefb[j + 1] - monedas)){
ans = max(ans, min(pref[i + 1] - monedas, prefb[j] - monedas));
i++;
}else{
ans = max(ans, min(pref[i] - monedas, prefb[j + 1] - monedas));
j++;
}
}
}
printf("%.4lf",(double)ans);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |