Submission #237998

# Submission time Handle Problem Language Result Execution time Memory
237998 2020-06-09T16:24:05 Z my99n Potatoes and fertilizers (LMIO19_bulves) C++14
64 / 100
197 ms 13288 KB
#include<bits/stdc++.h>
using namespace std;

long long v[500100];
long long ans = 0;
priority_queue<int> heap;

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int n; cin >> n;
  for (int i = 1; i <= n; i++) {
    int a, b; cin >> a >> b;
    v[i] = a-b + v[i-1];
  }
  for (int i = 1; i <= n; i++) {
    if (v[i] > v[n]) {ans += v[i]-v[n]; v[i] = v[n];} // v[n] can't be changed
    if (v[i] < 0) {ans += 0-v[i]; v[i] = 0;} // v[i] >= 0
    heap.push(v[i]);
    heap.push(v[i]);
    ans += heap.top() - v[i];
    heap.pop();
  }
  cout << ans << endl;
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 14 ms 1152 KB Output is correct
5 Correct 25 ms 1792 KB Output is correct
6 Correct 75 ms 3444 KB Output is correct
7 Correct 149 ms 6512 KB Output is correct
8 Correct 131 ms 6512 KB Output is correct
9 Correct 119 ms 10736 KB Output is correct
10 Correct 109 ms 8432 KB Output is correct
11 Correct 96 ms 8432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 14 ms 1152 KB Output is correct
5 Correct 25 ms 1792 KB Output is correct
6 Correct 75 ms 3444 KB Output is correct
7 Correct 149 ms 6512 KB Output is correct
8 Correct 131 ms 6512 KB Output is correct
9 Correct 119 ms 10736 KB Output is correct
10 Correct 109 ms 8432 KB Output is correct
11 Correct 96 ms 8432 KB Output is correct
12 Correct 42 ms 3704 KB Output is correct
13 Correct 95 ms 8944 KB Output is correct
14 Correct 145 ms 13228 KB Output is correct
15 Correct 121 ms 11376 KB Output is correct
16 Correct 130 ms 10736 KB Output is correct
17 Correct 111 ms 8436 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 6 ms 384 KB Output is correct
13 Correct 6 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 6 ms 512 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 14 ms 1152 KB Output is correct
12 Correct 25 ms 1792 KB Output is correct
13 Correct 75 ms 3444 KB Output is correct
14 Correct 149 ms 6512 KB Output is correct
15 Correct 131 ms 6512 KB Output is correct
16 Correct 119 ms 10736 KB Output is correct
17 Correct 109 ms 8432 KB Output is correct
18 Correct 96 ms 8432 KB Output is correct
19 Correct 42 ms 3704 KB Output is correct
20 Correct 95 ms 8944 KB Output is correct
21 Correct 145 ms 13228 KB Output is correct
22 Correct 121 ms 11376 KB Output is correct
23 Correct 130 ms 10736 KB Output is correct
24 Correct 111 ms 8436 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 6 ms 384 KB Output is correct
27 Correct 6 ms 384 KB Output is correct
28 Correct 5 ms 384 KB Output is correct
29 Correct 6 ms 512 KB Output is correct
30 Correct 5 ms 384 KB Output is correct
31 Correct 5 ms 384 KB Output is correct
32 Correct 49 ms 3712 KB Output is correct
33 Correct 108 ms 8944 KB Output is correct
34 Correct 197 ms 13288 KB Output is correct
35 Correct 161 ms 10732 KB Output is correct
36 Incorrect 145 ms 11372 KB Output isn't correct
37 Halted 0 ms 0 KB -