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
/*
 * ZAP
 * Autor: Szymon Tur
 */

#include <iostream>

using namespace std;

int n,m;
long long * kl;
int * piek;

int main()
{
	cin >> n >> m;
	kl = new long long [n+1];
	piek = new int [m];
	kl[0]=0;
	for (int i=1;i<=n;i++) cin >> kl[i];
	for (int i=0;i<m;i++) cin >> piek[i];
	long long tm,max,P;

	for (int i=0;i<m;i++)
	{
		P=piek[i];
		tm=0;
		max=0;
		for (int j=0;j<n;j++)
		{
			if (kl[j+1]-kl[j]<P+tm)
			{
				tm += P - kl[j+1] + kl[j];
				max += tm;
			}
			else tm=0;
		}
		cout << max << "\n";
	}
	delete [] kl;
	delete [] piek;
	return 0;
}