Submission #295439

# Submission time Handle Problem Language Result Execution time Memory
295439 2020-09-09T16:43:09 Z Bruteforceman Potatoes and fertilizers (LMIO19_bulves) C++11
64 / 100
1000 ms 15096 KB
#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 10;
long long pre[maxn];
int a[maxn], b[maxn];

int main() {
  int n;
  cin >> n;
  for(int i = 1; i <= n; i++) {
    cin >> a[i] >> b[i];
    pre[i] = pre[i - 1] + a[i] - b[i];
  }
  while(pre[n] > 0) {
    int cnt = 0;
    int best = 0, id = n;
    for(int i = n; i >= 1; i--) {
      if(pre[i] > 0) ++cnt;
      else --cnt;
      if(best < cnt) {
        best = cnt;
        id = i;
      }
    }
    long long minVal = pre[n];
    for(int i = id; i <= n; i++) {
      if(pre[i] > 0) minVal = min(minVal, pre[i]);
    }
    for(int i = id; i <= n; i++) {
      pre[i] -= minVal;
    }
  }
  long long ans = 0;
  for(int i = 1; i <= n; i++) ans += abs(pre[i]);
  cout << ans << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 41 ms 1432 KB Output is correct
5 Correct 76 ms 2608 KB Output is correct
6 Correct 312 ms 7672 KB Output is correct
7 Correct 626 ms 14968 KB Output is correct
8 Correct 501 ms 13048 KB Output is correct
9 Correct 476 ms 12408 KB Output is correct
10 Correct 285 ms 10104 KB Output is correct
11 Correct 277 ms 10232 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 41 ms 1432 KB Output is correct
5 Correct 76 ms 2608 KB Output is correct
6 Correct 312 ms 7672 KB Output is correct
7 Correct 626 ms 14968 KB Output is correct
8 Correct 501 ms 13048 KB Output is correct
9 Correct 476 ms 12408 KB Output is correct
10 Correct 285 ms 10104 KB Output is correct
11 Correct 277 ms 10232 KB Output is correct
12 Correct 157 ms 3960 KB Output is correct
13 Correct 378 ms 9084 KB Output is correct
14 Correct 631 ms 15096 KB Output is correct
15 Correct 502 ms 13068 KB Output is correct
16 Correct 455 ms 12408 KB Output is correct
17 Correct 276 ms 10088 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
6 Correct 12 ms 452 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 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 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 12 ms 452 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 7 ms 512 KB Output is correct
12 Correct 14 ms 384 KB Output is correct
13 Correct 15 ms 384 KB Output is correct
14 Correct 17 ms 384 KB Output is correct
15 Correct 9 ms 384 KB Output is correct
16 Correct 9 ms 384 KB Output is correct
17 Correct 6 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 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 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 12 ms 452 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 41 ms 1432 KB Output is correct
12 Correct 76 ms 2608 KB Output is correct
13 Correct 312 ms 7672 KB Output is correct
14 Correct 626 ms 14968 KB Output is correct
15 Correct 501 ms 13048 KB Output is correct
16 Correct 476 ms 12408 KB Output is correct
17 Correct 285 ms 10104 KB Output is correct
18 Correct 277 ms 10232 KB Output is correct
19 Correct 157 ms 3960 KB Output is correct
20 Correct 378 ms 9084 KB Output is correct
21 Correct 631 ms 15096 KB Output is correct
22 Correct 502 ms 13068 KB Output is correct
23 Correct 455 ms 12408 KB Output is correct
24 Correct 276 ms 10088 KB Output is correct
25 Correct 7 ms 512 KB Output is correct
26 Correct 14 ms 384 KB Output is correct
27 Correct 15 ms 384 KB Output is correct
28 Correct 17 ms 384 KB Output is correct
29 Correct 9 ms 384 KB Output is correct
30 Correct 9 ms 384 KB Output is correct
31 Correct 6 ms 384 KB Output is correct
32 Execution timed out 1089 ms 3960 KB Time limit exceeded
33 Halted 0 ms 0 KB -