Submission #587929

#TimeUsernameProblemLanguageResultExecution timeMemory
587929jmyszka2007Potatoes and fertilizers (LMIO19_bulves)C++17
100 / 100
212 ms15208 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { int n; scanf("%d", &n); vector<int>a(n + 1); vector<int>b(n + 1); for(int i = 1; i <= n; i++) { scanf("%d%d", &a[i], &b[i]); } ll ans = 0; ll d = 0; priority_queue<ll>q; for(int i = 1; i <= n; i++) { d += a[i] - b[i]; ans += abs(d); if(d < 0) { q.push(0); q.push(0); } else { q.push(d); q.push(d); } q.pop(); } while(!q.empty()) { ll x = q.top(); q.pop(); ans -= min(x, d); } printf("%lld\n", ans); }

Compilation message (stderr)

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