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

using namespace std;

int main()
{
	int n = 0;
	int m = 0;

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

	vector<int> client;
	client.resize(n);

	for (int i = 0; i < n; i++)
	{
		scanf("%d", &client[i]);
	}

	adjacent_difference(client.begin(), client.end(), client.begin());

	// for (const auto &i: client)
	// {
	// 	printf("%d, ", i);
	// }
	// printf("\n");

	while (m-- > 0)
	{
		int waitt = 0;
		scanf("%d", &waitt);

		unsigned long long int wait_sum = 0;
		int64_t leftover = 0;

		for (size_t ct = 0; ct < client.size(); ct++)
		{
			leftover = leftover + client[ct] - waitt;
			if (leftover < 0)
			{
				wait_sum += -leftover;
			}
			else
			{
				leftover = 0;
			}
		}
		printf("%llu\n", wait_sum);
	}
	return 0;
}