Submission #891429

# Submission time Handle Problem Language Result Execution time Memory
891429 2023-12-23T02:42:16 Z ClHg2 Potatoes and fertilizers (LMIO19_bulves) C++14
100 / 100
163 ms 11196 KB
#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

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 time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 11 ms 992 KB Output is correct
5 Correct 24 ms 1500 KB Output is correct
6 Correct 80 ms 2512 KB Output is correct
7 Correct 102 ms 6340 KB Output is correct
8 Correct 133 ms 5064 KB Output is correct
9 Correct 107 ms 5072 KB Output is correct
10 Correct 92 ms 5316 KB Output is correct
11 Correct 100 ms 4820 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 11 ms 992 KB Output is correct
5 Correct 24 ms 1500 KB Output is correct
6 Correct 80 ms 2512 KB Output is correct
7 Correct 102 ms 6340 KB Output is correct
8 Correct 133 ms 5064 KB Output is correct
9 Correct 107 ms 5072 KB Output is correct
10 Correct 92 ms 5316 KB Output is correct
11 Correct 100 ms 4820 KB Output is correct
12 Correct 36 ms 1500 KB Output is correct
13 Correct 92 ms 9412 KB Output is correct
14 Correct 106 ms 11196 KB Output is correct
15 Correct 135 ms 9420 KB Output is correct
16 Correct 147 ms 8676 KB Output is correct
17 Correct 92 ms 7176 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 388 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 388 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 472 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 464 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 388 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
11 Correct 11 ms 992 KB Output is correct
12 Correct 24 ms 1500 KB Output is correct
13 Correct 80 ms 2512 KB Output is correct
14 Correct 102 ms 6340 KB Output is correct
15 Correct 133 ms 5064 KB Output is correct
16 Correct 107 ms 5072 KB Output is correct
17 Correct 92 ms 5316 KB Output is correct
18 Correct 100 ms 4820 KB Output is correct
19 Correct 36 ms 1500 KB Output is correct
20 Correct 92 ms 9412 KB Output is correct
21 Correct 106 ms 11196 KB Output is correct
22 Correct 135 ms 9420 KB Output is correct
23 Correct 147 ms 8676 KB Output is correct
24 Correct 92 ms 7176 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 472 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 464 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 1 ms 604 KB Output is correct
32 Correct 1 ms 344 KB Output is correct
33 Correct 37 ms 3016 KB Output is correct
34 Correct 97 ms 10068 KB Output is correct
35 Correct 163 ms 11096 KB Output is correct
36 Correct 161 ms 8792 KB Output is correct
37 Correct 132 ms 9152 KB Output is correct
38 Correct 158 ms 11196 KB Output is correct
39 Correct 105 ms 7628 KB Output is correct
40 Correct 121 ms 7616 KB Output is correct
41 Correct 96 ms 6332 KB Output is correct
42 Correct 95 ms 6336 KB Output is correct
43 Correct 94 ms 7628 KB Output is correct
44 Correct 96 ms 7108 KB Output is correct
45 Correct 151 ms 11196 KB Output is correct
46 Correct 119 ms 7676 KB Output is correct
47 Correct 106 ms 8132 KB Output is correct