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>
using namespace std;

int n, m;
long long int tmp;

long long int calcTime(long long int k[], long long int p){
	long long int freeOvenTime = 0;
	long long int waitingTime = 0;
	for (int i=0 ; i< n ; i++){	
		long long int minTime = k[i]-p;	
		if (minTime >=0 && freeOvenTime<=minTime)
			freeOvenTime = k[i];
		else {
			freeOvenTime += p;
			waitingTime += (freeOvenTime - k[i]);
		}
	}
	return waitingTime;
}

int main(){
	scanf("%d",&n);
	scanf("%d",&m);

	long long int k[200005];
	long long int p[200005];
	
	for (int i=0 ; i< n ; i++){
		scanf ("%lld",&tmp);
		k[i] = tmp;	
	}
	
	for (int i=0; i<m ; i++){
		scanf("%lld",&tmp);
		p[i] = tmp;
	}
	
	for (int i=0 ; i <m ; i++)
		printf("%lld\n", calcTime(k, p[i]));
	return 0;
}