Submission #1018930

#TimeUsernameProblemLanguageResultExecution timeMemory
1018930JuliaTatadSure Bet (CEOI17_sure)C++17
100 / 100
106 ms6036 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]; } vector<int> x(n); vector<int> y(n); int j = 0; for (int i = 0; i < n; i++) { while (j < n && pa[i] > pb[min(n-1, j)]) { j++; } x[i] = j; //cout << "x[" << i << "] = " << x[i] << endl; } j = 0; for (int i = 0; i < n; i++) { while (j < n && pb[i] > pa[min(n - 1, j)]) { j++; } y[i] = j; } for (int i = 0; i < n; i++) { if (x[i] <= n - 1) { profit = MAX(profit, pa[i] - i - x[i] - 2); } if (y[i] <= n - 1) { profit = MAX(profit, pb[i] - i - y[i] - 2); } } printf("%.4lf", (double)profit); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...