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

unsigned long T[200001];
unsigned long P[200001];
unsigned long n, m;

unsigned long piekarnik (unsigned long p) {
	unsigned long min_pocz = 0, i = 0, razem = 0;
	while (i < n) {
		min_pocz += p;
		if (min_pocz > T[i]) {
			razem += (min_pocz - T[i]);
		} else {
			min_pocz = T[i];
		}
		i++;
	}
	return razem;
}

int main () {
        unsigned long i, a;
        scanf ("%ld %ld\n", &n, &m);
	i = 0;
	while (i < n) {
		scanf ("%ld", &a);
		T[i] = a;
		i++;
	}
        i = 0;
        while (i < m) {
                scanf ("%ld", &a);
                P[i] = a;
                i++;
	}
	i = 0;
	while (i < m) {
		printf ("%ld\n", piekarnik (P[i]));
		i++;
	}

	return 0;
}