Submission #299409

# Submission time Handle Problem Language Result Execution time Memory
299409 2020-09-14T20:55:48 Z Bruteforceman Potatoes and fertilizers (LMIO19_bulves) C++11
30 / 100
647 ms 11264 KB
#include <bits/stdc++.h>
using namespace std;


int main() {
  int n;
  cin >> n;
  vector <int> pre (n + 1);
  for(int i = 1; i <= n; i++) {
    int a, b;
    cin >> a >> b;
    pre[i] = pre[i - 1] + a - b;
  } 
  priority_queue <int> Q;
  long long base = 0;
  for(int i = 1; i <= n; i++) {
    if(pre[i] < 0) {
      base += -pre[i];
      pre[i] = 0;
    }
    if(pre[i] > pre[n]) {
      base += pre[i] - pre[n];
      pre[i] = pre[n];
    }
    Q.push(pre[i]);
    Q.push(pre[i]);
    if(pre[i] < Q.top()) {
      base += Q.top() - pre[i];
    }
    Q.pop();
  }
  cout << base << endl;
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 39 ms 1272 KB Output is correct
5 Correct 80 ms 2036 KB Output is correct
6 Correct 322 ms 5872 KB Output is correct
7 Correct 647 ms 11264 KB Output is correct
8 Incorrect 515 ms 9456 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 39 ms 1272 KB Output is correct
5 Correct 80 ms 2036 KB Output is correct
6 Correct 322 ms 5872 KB Output is correct
7 Correct 647 ms 11264 KB Output is correct
8 Incorrect 515 ms 9456 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 3 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 3 ms 384 KB Output is correct
15 Correct 4 ms 384 KB Output is correct
16 Correct 3 ms 384 KB Output is correct
17 Correct 5 ms 380 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 39 ms 1272 KB Output is correct
12 Correct 80 ms 2036 KB Output is correct
13 Correct 322 ms 5872 KB Output is correct
14 Correct 647 ms 11264 KB Output is correct
15 Incorrect 515 ms 9456 KB Output isn't correct
16 Halted 0 ms 0 KB -