1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>

using namespace std;

int main() {
    int n, m, i, j;
    cin >> n >> m;
    long long t [n];
    int d [m];
    for (i=0; i<n; i++)
        cin >> t[i];
    for (i=0; i<m; i++)
        cin >> d[i];

    for (i=0; i<m; i++) {
        long long s = d[i] < t[0] ? 0 : d[i] - t[0];
        for (j=1; j<n; j++)
            if (t[j] - t[j-1] < d[i])
                s+= d[i] - t[j] + t[j-1];
        cout << s << endl;
    }
}