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

long long int processOven(const int d, const std::vector<long long int>& clients)
{
	long long int delay = 0LL;
	long long int lastClientServed = 0;

	for (long long int client : clients) {
		if (client >= (lastClientServed + d)) {
			lastClientServed = client;
		} else {
			lastClientServed += d;
			delay += (lastClientServed - client);
		}
	}
	return delay;
}

int main()
{
	int n, m, d;
	long long int t;
	std::vector<long long int> clients;

	scanf("%d %d", &n, &m);
	for (int i = 0; i < n; ++i) {
		scanf("%lld", &t);
		clients.push_back(t);
	}

	for (int i = 0; i < m; ++i) {
		scanf("%d", &d);
		printf("%lld\n", processOven(d, clients));
	}

	return 0;
}