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
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <algorithm>

#include <unordered_map>

#include <vector>

#include <list>

#include <climits>

#include <utility>





using namespace std;

#define LL long long

#define INF 1000000000000000009LL

#define DBG(X) 

#define MAX_N 200010

int solve_nsquared(int n, int m, LL* t, LL* d, LL* wt)
{
	wt[0] = 0;
	LL* diffs = new LL[n+10];
	for (int i = 1; i < n; i++) {
		diffs[i] = t[i] - t[i - 1];
	}
	for (int j = 0; j < m; j++) {
		LL di = d[j];
		LL twt = 0;
		LL wtm1 = 0;
		LL wti = 0;
		for (int i = 1; i < n; i++) {
			wti = wtm1 + di - diffs[i];
			if (wti < 0) {
				wti = 0;
			}
			twt += wti;
			wtm1 = wti;
		}
		printf("%lld\n", twt);
	}
	delete[] diffs;
	return 0;
}


LL times[MAX_N];
LL piekarniki[MAX_N];
LL waiting_times[MAX_N];

int main() {
	int n, m;
	scanf("%d%d", &n, &m);
	times[0] = 0;
	for (int i = 0; i < n; i++)
	{
		scanf("%lld", &times[i+1]);
	}
	for (int i = 0; i < m; i++) {
		scanf("%lld", &piekarniki[i]);
	}
	//sort(piekarniki, piekarniki + m);
	solve_nsquared(n, m, times, piekarniki, waiting_times);
	return 0;
}