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
55
56
57
58
59
#include <iostream>
#include <vector>

using namespace std;

int pieczemy(vector<long> t, int p)
{
	int at = 0;
	bool piec = false;
	int poz = 0;
	int klient = 0;
	int suma = 0;
	while (true)
	{
		if (piec)
		{
			poz--;
			if (poz == 0)
			{
				piec = false;
				if (t[klient] < at)
				{
					suma += at - t[klient];
				}
				klient++;
				if (klient > t.size() - 1)
					return suma;
			}
		}
		if (!piec)
		{
			if (t[klient] <= at + p)
			{
				piec = true;
				poz = p;
			}
		}
		at++;
	}
}

int main()
{
	int n, m;
	vector<long> t;
	long a;
	cin >> n >> m;
	for (int i = 0; i < n; i++)
	{
		cin >> a;
		t.push_back(a);
	}
	for (int i = 0; i < m; i++)
	{
		cin >> a;
		cout << pieczemy(t, a) << endl;
	}
	return 0;
}