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

int breaksOrig[200000];
int breaks[200000];

int clientCount;
int ovenCount;

int main() {

	cin >> clientCount;
	cin >> ovenCount;

	int lastClient = 0;
	int currentClient;
	for (int i = 0; i < clientCount; i++) {
		cin >> currentClient;
		breaksOrig[i] = currentClient - lastClient;
		lastClient = currentClient;
	}

	int ovenCookTime;
	int nextDelay;
	int totalDelay;
	for (int i = 0; i < ovenCount; i++) {
		cin >> ovenCookTime;
		nextDelay = 0;
		totalDelay = 0;
		for(int j = 0; j < clientCount; j++) {
			breaks[j] = breaksOrig[j] - nextDelay;
			if(breaks[j] < ovenCookTime) {
				nextDelay = ovenCookTime - breaks[j];
				totalDelay += nextDelay;
			} else {
				nextDelay = 0;
			}
		}
		cout << totalDelay << "\n";
	}

	return 0;
}