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
#include <algorithm>
#include <cstdio>

using namespace std;

int n, m;

int main()
{
	long long at[200000] = { 0 };
	scanf("%d %d", &n, &m);
	for (int j = 0; j < n; j++)
		scanf("%lld", &at[j]);
	sort(at, at + n);
	for (int i = 0; i < m; i++)
	{
		long long t = 0;
		long long r = 0;
		long long d;
		scanf("%lld", &d);
		long long* ti;
		ti = at;
		for (int j=n; j > 0; --j)
		{
			t += d;
			if (t < *ti)
				t = *ti;
			else
				r += t - *ti;
			++ti;
		}
		printf("%lld\n", r);
	}

}