Submission #1018879

#TimeUsernameProblemLanguageResultExecution timeMemory
1018879JuliaTatadSure Bet (CEOI17_sure)C++17
60 / 100
2043 ms4772 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...