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

int main()
{
	int n, m;
	std::vector<long long> tabn;

	long long a, temp, rest, delay;
	int b;

	std::cin >> n >> m >> a;
	tabn.push_back(a);
	temp = a;
	for (int i = 1; i < n; i++)
	{
		std::cin >> a;
		tabn.push_back(a - temp);
		temp = a;
	}
	for (int i = 0; i < m; i++)
	{
		std::cin >> b;
		rest = 0;
		delay = 0;
		for (int j = 0; j < n; j++)
		{
			if (tabn[j] - rest < b)
			{
				rest += (b - tabn[j]);
				delay += rest;
			}
			else
			{
				rest = 0;
			}
		}
		std::cout << delay << '\n';
	}

	return 0;
}