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
#include <stdio.h>
#include <algorithm>


int main() {
    int n, m;
    scanf("%d %d", &n, &m);

    unsigned long long t[n];

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

	unsigned long long w, z, d, W;
	for (int j = 0; j < m; j++) {
	    scanf("%llu", &d);
	    W = z = 0;
	    for (int i = 0; i < n; i++) {
	        w = std::max((long long) (z + d - t[i]), 0ll);
	        z = t[i] + w;
            W += w;
	    }
	    printf("%llu\n", W);
	}

	return 0;
}