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

using namespace std;

typedef long long int ll;

ll t[5000];
ll d[5000];

int n,m;

void read() {
    cin >> n >> m;
    for(int i = 0; i < n; ++i) {
        cin >> t[i];
    }
    for(int j = 0; j < m; ++j) {
        cin >> d[j];
    }
}

ll solve(ll mt) {
    ll ans = 0;
    ll my_end = 0;
    for(int i = 0; i < n; ++i) {
        if(t[i]-mt < my_end) {
            ll to_add = my_end - (t[i]-mt);
            ans += to_add;
            my_end = t[i] + to_add;
        } else {
            my_end = t[i];
        }
    }
    return ans;
}

int main() {
    ios_base::sync_with_stdio(false);
    read();
    for(int i = 0; i < m; ++i) {
        cout << solve(d[i]) << endl;
    }
    return 0;
}