1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <iostream>

long long solve(int piek, long* ts, int tsn) {
  long prev = 0;
  long long sum = 0;

  for(int i = 0; tsn > i; i++) {
    prev = std::max(prev + piek, ts[i]);
    sum += std::max(0L, prev - ts[i]);
  }

  return sum;
}

int main() {
  int n;
  std::cin >> n;

  int m;
  std::cin >> m;

  auto* ts = new long[n];

  for(int i = 0; n > i; i++) {
    std::cin >> ts[i];
  }

  for(int i = 0; m > i; i++) {
    int piek;
    std::cin >> piek;
    std::cout << solve(piek, ts, n) << std::endl;
  }

  return 0;
}