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

using namespace std;

const uint32_t Max = 200000;

int main() {
    uint32_t i, j, n, m, d;
    uint64_t t[Max], lastEnd, waitTime;

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

    for (i=0; i<m; ++i) {
        cin >> d;
        lastEnd = 0;
        waitTime = 0;
        for (j=0; j<n; ++j) {
             waitTime += max(int64_t(0), int64_t(lastEnd+d) - int64_t(t[j]));
             lastEnd = max(t[j], lastEnd + d);
        }
        cout << waitTime;
        if (i != m-1) {
            cout << endl;
        }
    }

    return 0;
}