Submission #299410

# Submission time Handle Problem Language Result Execution time Memory
299410 2020-09-14T20:56:54 Z Bruteforceman Potatoes and fertilizers (LMIO19_bulves) C++11
100 / 100
703 ms 15336 KB
#include <bits/stdc++.h>
using namespace std;


int main() {
  int n;
  cin >> n;
  vector <long long> 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 <long long> 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 1396 KB Output is correct
5 Correct 79 ms 2292 KB Output is correct
6 Correct 327 ms 4500 KB Output is correct
7 Correct 661 ms 8624 KB Output is correct
8 Correct 533 ms 8424 KB Output is correct
9 Correct 477 ms 12648 KB Output is correct
10 Correct 308 ms 10472 KB Output is correct
11 Correct 308 ms 10472 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 39 ms 1396 KB Output is correct
5 Correct 79 ms 2292 KB Output is correct
6 Correct 327 ms 4500 KB Output is correct
7 Correct 661 ms 8624 KB Output is correct
8 Correct 533 ms 8424 KB Output is correct
9 Correct 477 ms 12648 KB Output is correct
10 Correct 308 ms 10472 KB Output is correct
11 Correct 308 ms 10472 KB Output is correct
12 Correct 163 ms 4208 KB Output is correct
13 Correct 399 ms 11112 KB Output is correct
14 Correct 668 ms 15208 KB Output is correct
15 Correct 525 ms 13452 KB Output is correct
16 Correct 471 ms 12780 KB Output is correct
17 Correct 305 ms 10472 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 0 ms 288 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 2 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 288 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 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
11 Correct 3 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
13 Correct 4 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 3 ms 384 KB Output is correct
16 Correct 3 ms 384 KB Output is correct
17 Correct 4 ms 384 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 288 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 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
11 Correct 39 ms 1396 KB Output is correct
12 Correct 79 ms 2292 KB Output is correct
13 Correct 327 ms 4500 KB Output is correct
14 Correct 661 ms 8624 KB Output is correct
15 Correct 533 ms 8424 KB Output is correct
16 Correct 477 ms 12648 KB Output is correct
17 Correct 308 ms 10472 KB Output is correct
18 Correct 308 ms 10472 KB Output is correct
19 Correct 163 ms 4208 KB Output is correct
20 Correct 399 ms 11112 KB Output is correct
21 Correct 668 ms 15208 KB Output is correct
22 Correct 525 ms 13452 KB Output is correct
23 Correct 471 ms 12780 KB Output is correct
24 Correct 305 ms 10472 KB Output is correct
25 Correct 3 ms 384 KB Output is correct
26 Correct 4 ms 384 KB Output is correct
27 Correct 4 ms 384 KB Output is correct
28 Correct 4 ms 384 KB Output is correct
29 Correct 3 ms 384 KB Output is correct
30 Correct 3 ms 384 KB Output is correct
31 Correct 4 ms 384 KB Output is correct
32 Correct 173 ms 4080 KB Output is correct
33 Correct 413 ms 11008 KB Output is correct
34 Correct 690 ms 15336 KB Output is correct
35 Correct 521 ms 12776 KB Output is correct
36 Correct 542 ms 13468 KB Output is correct
37 Correct 703 ms 15336 KB Output is correct
38 Correct 380 ms 11420 KB Output is correct
39 Correct 384 ms 10984 KB Output is correct
40 Correct 317 ms 10600 KB Output is correct
41 Correct 317 ms 10472 KB Output is correct
42 Correct 310 ms 10472 KB Output is correct
43 Correct 317 ms 10472 KB Output is correct
44 Correct 664 ms 15336 KB Output is correct
45 Correct 362 ms 10728 KB Output is correct
46 Correct 347 ms 10344 KB Output is correct
47 Correct 2 ms 384 KB Output is correct