Submission #616919

#TimeUsernameProblemLanguageResultExecution timeMemory
616919nghiass001Sure Bet (CEOI17_sure)C++17
100 / 100
101 ms5172 KiB
#include <bits/stdc++.h> #define FOR(i, l, r) for(int i=(l); i<=(r); ++i) #define REP(i, l, r) for(int i=(l); i<(r); ++i) #define FORD(i, r, l) for(int i=(r); i>=(l); --i) #define REPD(i, r, l) for(int i=(r)-1; i>=(l); --i) using namespace std; const int N = 1e5 + 5; int n; long double a[N], b[N]; void Enter() { cin >> n; FOR(i, 1, n) cin >> a[i] >> b[i]; } void Process() { sort(a + 1, a + n + 1, greater<long double>()); sort(b + 1, b + n + 1, greater<long double>()); long double res = 0, sumL = 0, sumR = 0; for(int i = 1, j = 1; i <= n || j <= n; ) { if (j > n || i <= n && sumL < sumR) sumL += a[i++]; else sumR += b[j++]; res = max(res, min(sumL, sumR) - (i + j - 2)); } cout << setprecision(4) << fixed << res; } int main() { #define file "sure" if (fopen(file".inp", "r")) { freopen(file".inp", "r", stdin); freopen(file".out", "w", stdout); } ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); Enter(); Process(); }

Compilation message (stderr)

sure.cpp: In function 'void Process()':
sure.cpp:22:29: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   22 |         if (j > n || i <= n && sumL < sumR) sumL += a[i++];
      |                      ~~~~~~~^~~~~~~~~~~~~~
sure.cpp: In function 'int main()':
sure.cpp:33:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |         freopen(file".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
sure.cpp:34:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   34 |         freopen(file".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...