답안 #513014

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
513014 2022-01-17T00:56:53 Z CrouchingDragon Potatoes and fertilizers (LMIO19_bulves) C++17
100 / 100
162 ms 12540 KB
#include <bits/stdc++.h>
int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);
  int N;
  std::cin >> N;
  std::vector<int64_t> a(N);
  for (int i = 0; i < N; ++i) {
    int64_t x, y;
    std::cin >> x >> y;
    a[i] = x - y;
  }
  std::priority_queue<int64_t> pq;
  pq.push(0);
  int64_t sum = 0, cost = 0;
  for (int i = 0; i < N - 1; ++i) {
    sum += a[i];
    pq.push(sum);
    if (!pq.empty() && sum < pq.top()) {
      cost += pq.top() - sum;
      if (pq.top() != 0) pq.pop();
      pq.push(sum);
    }
  }
  sum += a[N - 1];
  while (!pq.empty() && pq.top() > sum) {
    cost += pq.top() - sum;
    pq.pop();
  }
  std::cout << cost << '\n';
  exit(0);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 16 ms 1352 KB Output is correct
5 Correct 31 ms 2260 KB Output is correct
6 Correct 88 ms 4452 KB Output is correct
7 Correct 99 ms 12524 KB Output is correct
8 Correct 135 ms 8436 KB Output is correct
9 Correct 130 ms 12540 KB Output is correct
10 Correct 79 ms 8452 KB Output is correct
11 Correct 85 ms 8444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 16 ms 1352 KB Output is correct
5 Correct 31 ms 2260 KB Output is correct
6 Correct 88 ms 4452 KB Output is correct
7 Correct 99 ms 12524 KB Output is correct
8 Correct 135 ms 8436 KB Output is correct
9 Correct 130 ms 12540 KB Output is correct
10 Correct 79 ms 8452 KB Output is correct
11 Correct 85 ms 8444 KB Output is correct
12 Correct 47 ms 3476 KB Output is correct
13 Correct 107 ms 6868 KB Output is correct
14 Correct 98 ms 12524 KB Output is correct
15 Correct 131 ms 8436 KB Output is correct
16 Correct 162 ms 8456 KB Output is correct
17 Correct 61 ms 8436 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 328 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 16 ms 1352 KB Output is correct
12 Correct 31 ms 2260 KB Output is correct
13 Correct 88 ms 4452 KB Output is correct
14 Correct 99 ms 12524 KB Output is correct
15 Correct 135 ms 8436 KB Output is correct
16 Correct 130 ms 12540 KB Output is correct
17 Correct 79 ms 8452 KB Output is correct
18 Correct 85 ms 8444 KB Output is correct
19 Correct 47 ms 3476 KB Output is correct
20 Correct 107 ms 6868 KB Output is correct
21 Correct 98 ms 12524 KB Output is correct
22 Correct 131 ms 8436 KB Output is correct
23 Correct 162 ms 8456 KB Output is correct
24 Correct 61 ms 8436 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 328 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 32 ms 2452 KB Output is correct
34 Correct 81 ms 6876 KB Output is correct
35 Correct 132 ms 8408 KB Output is correct
36 Correct 118 ms 8444 KB Output is correct
37 Correct 108 ms 8448 KB Output is correct
38 Correct 119 ms 8436 KB Output is correct
39 Correct 72 ms 8444 KB Output is correct
40 Correct 76 ms 8068 KB Output is correct
41 Correct 67 ms 8432 KB Output is correct
42 Correct 71 ms 8440 KB Output is correct
43 Correct 75 ms 8436 KB Output is correct
44 Correct 69 ms 8380 KB Output is correct
45 Correct 148 ms 8380 KB Output is correct
46 Correct 80 ms 8436 KB Output is correct
47 Correct 77 ms 7596 KB Output is correct