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
53
54
55
56
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
#define int long long
    int n, m;
    cin >> n >> m;

    vector<int> t(n+1, 0);

    int mini = std::numeric_limits<int>::max(), maxi = 0;

    long long sum = 0;

    for(int i = 1; i <= n; ++i) {
        cin >> t[i];
        sum += t[i];
        mini = std::min(mini, t[i]-t[i-1]);
        maxi = std::max(maxi, t[i]-t[i-1]);
    }

    for(int _ = 1; _ <= m; ++_) {
        int d;
        cin >> d;

        if (d <= mini) {
            printf("0\n");
            continue;
        }
        if (d >= maxi) {
            long long now = d*n*(n+1)/2 - sum;
            printf("%lld\n", now);
            continue;
        }

        vector<int> w(n+1, 0);

        w[0] = 0;

        int slack = 0;



        for(int i = 1; i <= n; ++i) {
            w[i] = max(w[i-1]+d, t[i]);
//            printf("Client %d at %d: w[%d] = %d. Waiting %d\n", i, t[i], i, w[i], w[i] - t[i]);

            slack += w[i] - t[i];
        }
        printf("%lld\n", slack);
    }
    return 0;
}