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 <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
double MAX(double a, double b) {
if (a > b) {
return a;
}
return b;
}
double MIN(double a, double b) {
if (a < b) {
return a;
}
return b;
}
int main() {
int n; cin >> n; double profit = 0;
vector<double> a(n); vector<double> b(n);
for (int i = 0; i < n; i++) {
cin >> a[i]; cin >> b[i];
}
sort(a.begin(), a.end()); reverse(a.begin(), a.end()); sort(b.begin(), b.end()); reverse(b.begin(), b.end());
vector<double> pa(n); vector<double> pb(n);
pa[0] = a[0]; pb[0] = b[0];
for (int i = 1; i < n; i++) {
pa[i] = pa[i - 1] + a[i]; pb[i] = pb[i - 1] + b[i];
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
profit = MAX(profit, MIN(pa[i], pb[j]) - i - j - 2);
}
}
printf("%.4lf", (double)profit);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |