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

using namespace std;

const int N_MAX = 200000;
const int M_MAX = 200000;

long long int T[N_MAX];
int D[M_MAX];

long long int get_result(int n, int d) {
	long long int result = 0;
	long long int pop = 0;
	for (int i = 0; i < n; ++i) {
		long long int pocz = max(T[i] - d, pop);
		long long int kon = pocz + d;
		result += max(kon - T[i], 0LL);
		pop = kon;
		//printf("%lld %lld %lld\n", pocz, kon, result);
	}
	return result;
}

int main() {
	int n, m;
	scanf("%d %d", &n, &m);
	for (int i = 0; i < n; ++i) {
		scanf("%lld", &T[i]);
	}
	for (int i = 0; i < m; ++i) {
		scanf("%d", &D[i]);
	}
	for (int i = 0; i < m; ++i) {
		printf("%lld\n", get_result(n, D[i]));
	}
	return 0;
}