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
#include <iostream>
#include <stdio.h>

using namespace std;

int main(int argc, char const *argv[]){
	int n, m;
	scanf("%d", &n);
	scanf("%d", &m);
	long long T1[n+1];
	T1[0]=0;
	long long T2[n], wynik[m];
	for (int i = 1; i < n+1; ++i)
	{
		long long a;
		scanf("%lld", &a);
		T1[i]=a;
		T2[i-1]=T1[i]-T1[i-1];
	}
	for (int i = 0; i < m; ++i)
	{
		int a;
		scanf("%d", &a);
		long long op=0, max=0;
		for (int i = 0; i < n; ++i)
		{
			if(T2[i]-op<a)
			{
				op=op-T2[i]+a;
				// cout<<"<"<<op<<">";
				max=max+op;
			}
			else
			{
				// cout<<"|"<<i<<"|";
				op=0;
			}
		}
		// cout<<endl;
		wynik[i]=max;
	}

	for (int i = 0; i < m; ++i)
	{
		printf("%lld\n", wynik[i]);
	}


	return 0;
}