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

using namespace std;

const int MAX_N =  2 *  (int)1e5 +1;
typedef long long ll;

ll Clients[MAX_N];

ll my_max(ll a, ll b){
    if(a < b){
        return b;
    }

    return a;
}

ll findClientWaitTime(ll ovenTime, int n){

    ll ovenAvailableTime = 0;
    ll totalWaitTime = 0;

    for(int i =0; i < n; i++){
        ll t = Clients[i];
        ll clientWaitTime = my_max(0,ovenAvailableTime +  ovenTime - t);
        totalWaitTime += clientWaitTime;

        ovenAvailableTime = my_max(t, t+clientWaitTime );
    }

    return totalWaitTime;
}

int main() {

    int n,m;
    cin >> n >> m;

    for(int i=0; i <n; ++i){
        cin >> Clients[i];
    }

    for(int i=0; i <m ; ++i){
        ll ovenTime;
        cin >>  ovenTime;
        cout << findClientWaitTime(ovenTime, n) << endl;

    }

    return 0;
}