Submission #701619

#TimeUsernameProblemLanguageResultExecution timeMemory
701619GrandTiger1729Sure Bet (CEOI17_sure)C++17
0 / 100
1 ms260 KiB
#include <iostream> #include <iomanip> #include <algorithm> using namespace std; int main(){ cin.tie(0)->sync_with_stdio(0); cout << fixed << setprecision(4); int n; cin >> n; double a[n], b[n]; for (int i = 0; i < n; i++){ cin >> a[i] >> b[i]; } sort(a, a + n, greater<double>()); sort(b, b + n, greater<double>()); double prefa[n + 1]{}, prefb[n + 1]{}; for (int i = 0; i < n; i++){ prefa[i + 1] = prefa[i] + a[i] - 1; prefb[i + 1] = prefb[i] + b[i] - 1; } double ans = 0; // for (int i = 0; i <= n; i++){ // for (int j = 0; j <= n; j++){ // ans = max(ans, min(prefa[i] - j, prefb[j] - i)); // if (prefa[i] - j < prefb[j] - i) // cout << "A"; // else // cout << "B"; // } // cout << endl; // } int pa = 0, pb = 0; do{ if (prefa[pa] < prefb[pb]) pa++; else pb++; ans = max(ans, min(prefa[pa] - pb, prefb[pb] - pa)); }while (pa <= n && pb <= n); do{ pa++; ans = max(ans, min(prefa[pa] - pb, prefb[pb] - pa)); }while (pa <= n); do{ pb++; ans = max(ans, min(prefa[pa] - pb, prefb[pb] - pa)); }while (pb <= n); cout << ans << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...