Submission #237997

# Submission time Handle Problem Language Result Execution time Memory
237997 2020-06-09T16:22:21 Z my99n Potatoes and fertilizers (LMIO19_bulves) C++14
30 / 100
152 ms 11200 KB
#include<bits/stdc++.h>
using namespace std;

int 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 256 KB Output is correct
2 Correct 6 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 2040 KB Output is correct
6 Correct 68 ms 5876 KB Output is correct
7 Correct 152 ms 11200 KB Output is correct
8 Incorrect 122 ms 9328 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 6 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 2040 KB Output is correct
6 Correct 68 ms 5876 KB Output is correct
7 Correct 152 ms 11200 KB Output is correct
8 Incorrect 122 ms 9328 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 6 ms 384 KB Output is correct
3 Correct 5 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 256 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 256 KB Output is correct
2 Correct 6 ms 384 KB Output is correct
3 Correct 5 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 256 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 512 KB Output is correct
13 Correct 6 ms 512 KB Output is correct
14 Correct 6 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 6 ms 384 KB Output is correct
17 Correct 5 ms 512 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 6 ms 384 KB Output is correct
3 Correct 5 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 256 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 2040 KB Output is correct
13 Correct 68 ms 5876 KB Output is correct
14 Correct 152 ms 11200 KB Output is correct
15 Incorrect 122 ms 9328 KB Output isn't correct
16 Halted 0 ms 0 KB -