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
44
45
46
47
48
49
50
#include <iostream>
#include <stdio.h>

using namespace std;


int main() {

	unsigned long long int i = 0;
	unsigned long long int j = 0;
	long long int tmp = 0;
	unsigned long long int n;
	unsigned long long int m;

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

	unsigned long long tstart = 0;
	unsigned long long tsum = 0;
	unsigned long long twait = 0;

	for(j = 0 ; j < m ; j++) {
		for(i = 0 ; i < n ; i++) {
			tmp = t[i] - p[j];
			if (tmp > 0) {
				tstart = tmp;
			}
			if (tstart < tsum) {
				tstart = tsum;
			}
			tsum = tstart + p[j];
			if (tsum > t[i]) {
				twait += tsum - t[i];
			}
		}
		printf("%llu\n", twait);
		twait = 0;
		tsum = 0;
		tstart = 0;
	}

	return 0;
}