Submission #384122

#TimeUsernameProblemLanguageResultExecution timeMemory
384122LucaDantasPotatoes and fertilizers (LMIO19_bulves)C++17
0 / 100
1 ms364 KiB
#include <cstdio> #include <queue> std::priority_queue<long long> q; int main() { long long d, ans = 0; int n; scanf("%d", &n); for(int i = 0; i < n; i++) { int a, b; scanf("%d %d", &a, &b); d += a - b; if(d < 0) ans += -d; if(q.size() && d < q.top()) ans += q.top() - (d<0?0:d), q.pop(), q.push(d<0?0:d); q.push(d<0?0:d); } printf("%lld\n", ans); }

Compilation message (stderr)

bulves.cpp: In function 'int main()':
bulves.cpp:8:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    8 |  int n; scanf("%d", &n);
      |         ~~~~~^~~~~~~~~~
bulves.cpp:10:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   10 |   int a, b; scanf("%d %d", &a, &b);
      |             ~~~~~^~~~~~~~~~~~~~~~~
bulves.cpp:11:5: warning: 'd' may be used uninitialized in this function [-Wmaybe-uninitialized]
   11 |   d += a - b;
      |   ~~^~~~~~~~
#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...