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
#include <algorithm>
#include <vector>
#include <map>
#include <cstdio>
using namespace std;

int main() {
	int n, m;
	scanf("%d", &n);
	scanf("%d", &m);
	long long t[200001];
	int d[200001];
	for (int i = 0; i < n; ++i) {
		scanf("%lld", &t[i]);
	}
	for (int i = 0; i < m; ++i) {
		scanf("%d", &d[i]);
	}
	map<long long, long long> cache;
	sort(t, t + n);
	for (int i = 0; i < m; ++i) {
		long long time = d[i];
		if (cache.find(time) == cache.end()) {
			long long result = 0;
			long long start = 0;
			for (int j = 0; j < n; ++j) {
				long long end = max(start + time, t[j]);
				result += (end - t[j]);
				start = end;
			}
			cache[time] = result;
			printf("%lld\n", result);
		}
		else {
			printf("%lld\n", cache[time]);
		}
	}
	return 0;
}