Submission #1286491

#TimeUsernameProblemLanguageResultExecution timeMemory
1286491CrabCNHPotatoes and fertilizers (LMIO19_bulves)C++20
100 / 100
163 ms16416 KiB
#include <bits/stdc++.h> #define task "htgdtctn" #define int long long #define pii pair <int, int> #define fi first #define se second #define szf sizeof #define sz(s) (int)((s).size()) #define all(v) (v).begin(), (v).end() using namespace std; template <class T> void minimize (T &t, T f) {if (t > f) t = f;} template <class T> void maximize (T &t, T f) {if (t < f) t = f;} const int maxN = 5e5 + 5; const int inf = 1e18 + 7; const int mod = 1e9 + 7; // mt19937_64 rd (chrono :: steady_clock :: now ().time_since_epoch ().count ()); // int Rand (int l, int r) {return uniform_int_distribution <int> (l, r) (rd);} pii a[maxN]; int b[maxN]; inline void Solve () { int n; cin >> n; for (int i = 1; i <= n; i ++) { cin >> a[i].fi >> a[i].se; b[i] = a[i].fi - a[i].se + b[i - 1]; } int res = 0; priority_queue <int> pq; for (int i = 1; i < n; i ++) { if (b[i] < 0) { res += -b[i]; b[i] = 0; } res += b[i]; pq.push (b[i]); pq.push (b[i]); pq.pop (); } while (!pq.empty ()) { int val = pq.top (); pq.pop (); res -= min (val, b[n]); } cout << res; return; } signed main () { cin.tie (nullptr) -> sync_with_stdio (false); if (fopen (task".inp", "r")) { freopen (task".inp", "r", stdin); freopen (task".out", "w", stdout); } int t = 1; //cin >> t; while (t --) { Solve (); } return 0; } // wake me up when September ends

Compilation message (stderr)

bulves.cpp: In function 'int main()':
bulves.cpp:59:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   59 |         freopen (task".inp", "r", stdin);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
bulves.cpp:60:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   60 |         freopen (task".out", "w", stdout);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...