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

using namespace std;

int main() {
    int N,M;
    cin >> N;
    cin >> M;
    long long T[N];
    int D[M];

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

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

    long long ANS[M];
    for (int i=0; i<M; i++) ANS[i] = 0;

    for (int i = 0; i < M; i++) {
        long long last = 0;

        for (int j = 0; j < N; j++) {
            long long take = std::max(0LL, last + D[i] - T[j]);
            ANS[i] += take;
            last = T[j] + take;
        }
    }
    for (int i=0; i<M; i++){
        cout << ANS[i] << endl;
    }
    return 0;
}