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
using namespace std;
#include <cstdio>
#include <algorithm>
typedef long long int LL;
const int N = 201718+50;
LL tab[N];

inline LL max(LL a, LL b)
{
    return a > b ? a : b;
}

int main () {
  LL n, m, prev, tmp, d;
  scanf("%lld %lld %lld", &n, &m, &prev);
  tab[0] = prev;
  for(LL i = 1; i < n; ++i)
  {
    scanf("%lld", &tmp);
    tab[i] = tmp-prev;
    prev = tmp;
  }
  for(LL i = 0; i < m; ++i)
  {
    LL sum = 0, curr = 0;
    scanf("%lld", &d);
    for(LL j = 0; j < n; ++j)
    {
        curr = max(0, curr+d-tab[j]);
        sum += curr;
    }
    printf("%lld\n", sum);
  }
  return 0;
}