Submission #329076

#TimeUsernameProblemLanguageResultExecution timeMemory
329076NirjhorPotatoes and fertilizers (LMIO19_bulves)C++17
100 / 100
196 ms19272 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 500010; priority_queue <ll> pq; int n; ll a[N], b[N], steady; int main() { scanf("%d", &n); for (int i = 1; i <= n; ++i) { scanf("%lld %lld", a + i, b + i); a[i] -= b[i], a[i] += a[i - 1]; } ll extra = 0; for (int i = 1; i <= n; ++i) { if (a[i] < 0) extra -= a[i], a[i] = 0; if (a[i] > a[n]) extra += a[i] - a[n], a[i] = a[n]; pq.emplace(a[i]); pq.emplace(a[i]); steady += pq.top() - a[i]; pq.pop(); } steady += extra; cout << steady << '\n'; return 0; }

Compilation message (stderr)

bulves.cpp: In function 'int main()':
bulves.cpp:13:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   13 |   scanf("%d", &n);
      |   ~~~~~^~~~~~~~~~
bulves.cpp:15:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   15 |     scanf("%lld %lld", a + i, b + i);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...