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

using namespace std;

int main()
{
    int n, m;
    long long res, d, last, st;
    scanf("%d%d", &n, &m);

    vector<long long> t(n);

    for(int i = 0;i < n;++i)
    {
        scanf("%lld", &t[i]);
    }

    while(m--)
    {
        scanf("%lld", &d);
        res = 0;
        last = 0;

        for(int i = 0;i < n;++i)
        {
            st = max(t[i]-d, last);
            res += (st+d)-t[i];
            last = st+d;
        }
        printf("%lld\n", res);
    }

    return 0;
}