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

int main() {
	int clients_amount;
	int mashines_amount;
	cin >> clients_amount;
	cin >> mashines_amount;
	
	long long clients[clients_amount];
	long long diff[clients_amount];
	long long last_wait = 0;
	
	for (int i = 0; i < clients_amount; i++) {
		cin >> clients[i];
		diff[i] = clients[i] - last_wait;
		last_wait =  clients[i];
	}

	long long last = 0;
	long long timeNeeded = 0;
	long long sum = 0;
	long long mashine;

	for (int m = 0; m < mashines_amount; m++) {
		sum = 0;
		last =0;
		cin >> mashine;
		for (int i = 0; i < clients_amount; i++) {
			last += mashine - diff[i];
			if (last < 0) {
				last =0;
			} else {
				sum += last;
			}
		}
		cout << sum;
		cout << '\n';
	}
	return 0;
}