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
#include <bits/stdc++.h>

using namespace std;

#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__)
#define getchar_unlocked() getchar()
#define putchar_unlocked(a) putchar(a)
#endif

template<class T = uint64_t>
inline T readUInt(){
  T ret = 0;
  char tmp;
  while(tmp = getchar_unlocked(), tmp != '\n' && tmp != ' '){
    ret *= 10;
    ret += tmp - '0';
  }
  return ret;
}

template<class T>
inline void putUInt(T arg){
  char chars[20];
  int digits = 0;
  do {
    chars[digits++] = (arg%10) + '0';
    arg /= 10;
  } while(arg);
  while(digits) putchar_unlocked(chars[--digits]);
}

int main(){
  uint64_t n = readUInt(), m = readUInt(), sum;
  int64_t d, prev = 0, tmp;
  vector<int64_t> t(n);
  scanf(" ");
  for(auto &i : t){
    tmp = readUInt<int64_t>();
    i = (tmp - prev);
    prev = tmp;
  }
  scanf(" ");
  for(uint32_t i = 0; i < m; ++i){
    d = readUInt();
    sum = 0;
    prev = 0;
    for(int64_t &j : t){
      prev = max(0ll, d - j + prev);
      sum += prev;
    }
    putUInt(sum);
    putchar_unlocked('\n');
  }
}