Submission #623564

#TimeUsernameProblemLanguageResultExecution timeMemory
623564ipaljakPotatoes and fertilizers (LMIO19_bulves)C++14
100 / 100
140 ms15224 KiB
#include <bits/stdc++.h> using namespace std; typedef long long llint; const int MAXN = 5e5 + 10; int n; llint sum; llint a[MAXN]; int main(void) { scanf("%d", &n); for (int i = 0; i < n; ++i) { int x, y; scanf("%d%d", &x, &y); if (i > 0) a[i] = a[i - 1]; a[i] += (llint)(x - y); } llint sol = 0; for (int i = 0; i < n; ++i) { if (a[i] < 0) { sol += -a[i]; a[i] = 0; } if (a[i] > a[n - 1]) { sol += a[i] - a[n - 1]; a[i] = a[n - 1]; } } priority_queue<llint> Q; for (int i = 0; i < n; ++i) { Q.push(a[i]); if (Q.top() > a[i]) { sol += Q.top() - a[i]; Q.pop(); Q.push(a[i]); } } printf("%lld\n", sol); return 0; }

Compilation message (stderr)

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