Submission #621058

#TimeUsernameProblemLanguageResultExecution timeMemory
621058prarieSure Bet (CEOI17_sure)C++14
100 / 100
67 ms3612 KiB
#include <bits/stdc++.h> #define fastio ios_base::sync_with_stdio(0), cin.tie(0) #define endl '\n' #define fi first #define se second #define sz(v) (int)(v).size() #define all(v) (v).begin(), (v).end() #define compress(v) sort(all(v)), (v).erase(unique(all((v))), v.end()) #define pb push_back #define eb emplace_back using namespace std; using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; using ld = long double; template <typename T> inline void Mx(T &x, T y) { x < y && (x = y); } template <typename T> inline void Mn(T &x, T y) { x > y && (x = y); } int main() { int N; scanf("%d", &N); vector<double> A(N), B(N); for (int i = 0; i < N; i++) { scanf("%lf %lf", &A[i], &B[i]); } sort(all(A)); reverse(all(A)); sort(all(B)); reverse(all(B)); double ans = 0; double Asum = 0, Bsum = 0; int Aptr = 0, Bptr = 0; for (int x = 1; x <= 2 * N; x++) { if (Aptr == N) { Bsum += B[Bptr++]; } else if (Bptr == N) { Asum += A[Aptr++]; } else { if (Asum == Bsum) { if (A[Aptr] < B[Bptr]) { Bsum += B[Bptr++]; } else { Asum += A[Aptr++]; } } else if (Asum > Bsum) { Bsum += B[Bptr++]; } else { Asum += A[Aptr++]; } } ans = max(ans, min(Asum, Bsum) - x); } printf("%.4lf", ans); return 0; }

Compilation message (stderr)

sure.cpp: In function 'int main()':
sure.cpp:28:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |  scanf("%d", &N);
      |  ~~~~~^~~~~~~~~~
sure.cpp:32:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   32 |   scanf("%lf %lf", &A[i], &B[i]);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...