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
#include <iostream>

using namespace std;

int main()
{
    int clientsNumber, ovensNumber;
    cin >> clientsNumber;
    cin >> ovensNumber;
    
    long long int arrivals[clientsNumber];
    
    for (int i = 0; i < clientsNumber; i++) {
        cin >> arrivals[i];
    }
    
    for (int i = 0; i < ovensNumber; i++) {
        long long int ovenBakingTime;
        cin >> ovenBakingTime;
        long long int fastestAvailable = ovenBakingTime;
        long long int waitingTime = 0;
        for (int j = 0; j < clientsNumber; j++) {
            long long int currentClientWaitingTime = fastestAvailable - arrivals[j];
            fastestAvailable = arrivals[j] + ovenBakingTime;
            if (currentClientWaitingTime > 0) {
                waitingTime += currentClientWaitingTime;
                fastestAvailable += currentClientWaitingTime;
            }
            
        }
        cout << waitingTime << endl;
    }


    return 0;
}