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
38
39
40
41
#include <iostream>

using namespace std;

long long ts[200000];
int n, m;

long long solve(long long d) {
  long long total_wait = 0;
  long long last_serving_time = 0;

  for (int i = 0; i < n; i++) {
    long long next_serving = last_serving_time + d;
    if (ts[i] < next_serving) {
      total_wait += next_serving - ts[i];
      last_serving_time = next_serving;
    } else {
      last_serving_time = ts[i];
    }
  }

  return total_wait;
}

int main() {
  ios::sync_with_stdio(false);

  cin >> n >> m;

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

  for (int i = 0; i < m; i++) {
    int d;
    cin >> d;
    cout << solve(d) << endl;
  }

  return 0;
}