Submission #891429

#TimeUsernameProblemLanguageResultExecution timeMemory
891429ClHg2Potatoes and fertilizers (LMIO19_bulves)C++14
100 / 100
163 ms11196 KiB
#include <bits/stdc++.h>
#define EVAL(x) #x " = " << (x)

using std::cin;
using std::cout;
using i64 = int64_t;

auto main() -> int {
  std::ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  auto n = 0;
  cin >> n;

  auto sum = i64{0}, ans = i64{0};
  auto heap = std::priority_queue<i64>{};
  for (auto i = 0; i < n; ++i) {
    auto x = 0, y = 0;
    cin >> x >> y;
    sum += x - y;
    if (sum < 0)
      ans -= sum, heap.emplace(0), heap.emplace(0);
    else
      ans += sum, heap.emplace(sum), heap.emplace(sum);
    heap.pop();
  }
  for (auto i = 0; i < n; ++i) ans -= std::min(sum, heap.top()), heap.pop();
  cout << ans << "\n";
}

Compilation message (stderr)

bulves.cpp:2: warning: "EVAL" redefined
    2 | #define EVAL(x) #x " = " << (x)
      | 
<command-line>: note: this is the location of the previous definition
#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...