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

typedef long long int lli;

lli calculate(std::vector<lli> &c, lli t) {
    lli begin = std::max(c[0] - t, lli(0));
    lli result = begin + t - c[0];

    for (unsigned int i = 1; i < c.size(); ++i) {
        begin = std::max(begin + t, c[i] - t);
        result += begin + t - c[i];
    }

    return result;
}

int main () {
    lli n;
    lli m;
    
    std::vector<lli> custs;
    std::vector<lli> ovens;

    std::cin >> n >> m;
    custs.resize(n);
    ovens.resize(m);
    
    for (unsigned int i = 0; i < n; ++i) { std::cin >> custs[i]; }
    for (unsigned int i = 0; i < m; ++i) { std::cin >> ovens[i]; }

    for (unsigned int i = 0; i < m; ++i) {
        std::cout << calculate(custs, ovens[i]) << std::endl;
    }

    return 0;
}