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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <cstdio>

const int KOSTKA = 1e6 + 7;
long long int BARTOSZ[KOSTKA];
bool HAZY[KOSTKA];

const int MX = 2e5 + 7;
long long int T[MX];
long long int P[MX];
int n, m;

long long int solve(long long int k) {
  if (HAZY[static_cast<int>(k)])
    return BARTOSZ[static_cast<int>(k)];

  //fprintf(stderr, "start solve for k equal to %lld\n", k);

  long long int delay = 0;
  long long int last = 0;

  for (int i = 1; i <= n; ++i) {
    if (last + k <= T[i]) {
      last = T[i];
    } else {
      last += k;
      delay += last - T[i];
    }
    //fprintf(stderr, "last = %lld delay = %lld\n", last, delay);
  }

  //fprintf(stderr, "exit from solve\n");

  HAZY[static_cast<int>(k)] = true;
  BARTOSZ[static_cast<int>(k)] = delay;

  return delay;
}


int main() {
  scanf("%d%d", &n, &m);

  for (int i = 1; i <= n; ++i) 
    scanf("%lld", &T[i]);

  for (int i = 1; i <= m; ++i) 
    scanf("%lld", &P[i]);


  for (int i = 1; i <= m; ++i)
    printf("%lld\n", solve(P[i]));


  return 0;
}