Submission #987061

#TimeUsernameProblemLanguageResultExecution timeMemory
987061aaaaaarrozSure Bet (CEOI17_sure)C++17
100 / 100
135 ms3732 KiB
#include <bits/stdc++.h> using namespace std; int n; vector<double> a, b; bool srt(double x, double y) { if(x == 0) return true; if(y == 0) return false; return x > y; } int main() { cin >> n; a = vector<double>(n + 1), b = vector<double>(n + 1); for(int i = 1; i <= n; i++) cin >> a[i] >> b[i]; sort(a.begin(), a.end(), srt); sort(b.begin(), b.end(), srt); for(int i = 1; i <= n; i++) { a[i] += a[i - 1]; b[i] += b[i - 1]; } // double res = 0; for(int i = 0; i <= n; i++) { int l = 0, r = n + 1, mid, ans; while(l<=r) { mid = (l + r) / 2; if(b[mid] <= a[i]) { ans = mid; l = mid + 1; } else r = mid - 1; } res = max(res, min(a[i], b[ans]) - i - ans); if(a[i] != b[ans] && ans != n) res = max(res, min(a[i], b[ans + 1]) - i - ans - 1); //cout << i << " " << ans << " " << res << "\n"; } for(int i = 0; i <= n; i++) { int l = 0, r = n + 1, mid, ans; while(l<=r) { mid = (l + r) / 2; if(a[mid] <= b[i]) { ans = mid; l = mid + 1; } else r = mid - 1; } res = max(res, min(b[i], a[ans]) - i - ans); if(b[i] != a[ans] && ans != n) res = max(res, min(b[i], a[ans + 1]) - i - ans - 1); //cout << i << " " << ans << " " << res << "\n"; } cout << fixed << setprecision(4) << res << "\n"; }

Compilation message (stderr)

sure.cpp: In function 'int main()':
sure.cpp:49:31: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
   49 |             if(b[i] != a[ans] && ans != n) res = max(res, min(b[i], a[ans + 1]) - i - ans - 1);
sure.cpp:36:31: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
   36 |             if(a[i] != b[ans] && ans != n) res = max(res, min(a[i], b[ans + 1]) - i - ans - 1);
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...