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
#include <bits/stdc++.h>
using namespace std;

int main (){
    int n, m;
    cin >> n >> m;
    long long T [n];
    for (int i = 0; i < n; ++i)
    cin >> T[i];
    //sort(T, T + n);
    int d;
    while(m--){
        cin >> d;
        long long last = 0;
        long long ans = 0;
        for (int i = 0; i < n; ++i){
            if (last + d > T[i]){
                ans += last + d - T [i];
                last += d;
            } else {
                last = T [i];
            }
        }
        cout << ans << endl;
    }
}