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 <cstdio>
#include <algorithm>

using namespace std;
const int MAXN = 200000;

long long t[MAXN + 5], d[MAXN + 5];
int n, k;

void brute();

int main() {
  scanf("%d %d", &n, &k);
  for(int i = 0; i < n; ++i) {
    scanf("%lld", &t[i]);
  }
  for(int i = 0; i < k; ++i) {
    scanf("%lld", &d[i]);
  }

  brute();
  return 0;
}

void brute() {
  for(int i = 0; i < k; ++i) {
    long long last = 0;
    long long res = 0;
    long long act = d[i];
    for(int j = 0; j < n; ++j) {
      long long pos = max(last, t[j] - act) + act;
      res += pos - t[j];
      last = pos;
    }
    printf("%lld\n", res);
  }
}