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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include <bits/stdc++.h>

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef vector<VI> VVI;
typedef pair<int, int> PII;

// #define int LL

#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define FORE(i, x) for (__typeof((x).begin()) i = (x).begin(); i != (x).end(); ++i)

template <typename T> void _debug(const char *msg, T t) {
  cerr << msg << "="<< t << "\n";
}

template <typename T, typename... R> void _debug(const char *msg, T t, R... r) {
  while(*msg != ',') cerr << *msg++;
  cerr << "=" << t << ", ";
  _debug(msg+1, r...);
}

#ifdef TEST_ON_LOCAL_MACHINE
#define LOCAL
#endif

#ifdef LOCAL
#define debug(...) _debug(#__VA_ARGS__, __VA_ARGS__)
#define debugv(x) { cerr << #x << " = "; FORE(itt, x) cerr << *itt << ", "; cerr << "\n"; }
#else
#define debug(...)
#define debugv(x)
#endif

int main() {
  #ifdef TEST_ON_LOCAL_MACHINE
  freopen("test.in", "r", stdin);
  #endif

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

  debug(n, m);

  VLL a(n), d(m), diff(n);
  REP(i, n)
    scanf("%lld", &a[i]);
  REP(i, m)
    scanf("%lld", &d[i]);

  

  debugv(a);
  debugv(d);

  diff[0] = a[0];
  FOR(i, 1, n-1) {
    diff[i] = a[i] - a[i-1];
  }

  debugv(diff);
  REP(i, m) {
    LL current_delay = 0;
    LL sum_of_delays = 0;

    REP(j, n) {
      current_delay = max(0ll, d[i] - diff[j] + current_delay);
      sum_of_delays += current_delay;

      debug(i, j, current_delay, sum_of_delays);
    }
    printf("%lld\n", sum_of_delays);
  }

  return 0;
}