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
36
37
#include <iostream>
#include <algorithm>

using namespace std;

long t[200010];
int n, m, d;

int main() {
  ios::sync_with_stdio(false);
  cin >> n >> m;

  for (int i = 0; i < n; ++i) {
    cin >> t[i];
  }

  for (int i = 0; i < m; ++i) {
    long v;
    cin >> v;


    long last = 0;
    long result = 0;

    for (int j = 0; j < n; ++j) {
      if (last + v > t[j]) {
        result += last+v-t[j];
      }
      last = max(last + v, t[j]); 
    }

    cout << result << endl;

  }
  
  return 0;
}