Submission #204673

#TimeUsernameProblemLanguageResultExecution timeMemory
204673nhhoPotatoes and fertilizers (LMIO19_bulves)C++14
100 / 100
220 ms15204 KiB
#include <bits/stdc++.h> using namespace std; int n; long long ans, x[500001]; priority_queue<long long> q; int main() { scanf("%d", &n); for (int i = 0; i < n; i++) { int ta, tb; scanf("%d%d", &ta, &tb); x[i + 1] = x[i] + ta - tb; } for (int i = 1; i < n; i++) { if (x[i] < 0) { ans -= x[i]; x[i] = 0; } else if (x[i] > x[n]) { ans += x[i] - x[n]; x[i] = x[n]; } q.push(x[i]); ans += q.top() - x[i]; q.push(x[i]); q.pop(); } printf("%lld\n", ans); }

Compilation message (stderr)

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