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
#include <iostream>
#include <vector>
#include <algorithm>

typedef long long ll;
using namespace std;
std::vector<ll> times;

ll solve(ll m)
{
	ll prev_end_time = std::max(times.front(), m);
	ll solution = std::max(0ll, m - times.front());
	for (int i = 1; i < times.size(); ++i)
	{
		solution += std::max(0ll, prev_end_time - times[i] + m);
		prev_end_time = std::max(times[i], prev_end_time + m);
	}

	return solution;
}

int main()
{
	ios::sync_with_stdio(false);
	int n, m;
	ll piekarnik;
	cin >> n >> m;
	times.resize(n);

	for(int i = 0; i < n; ++i)
	{
		cin >> times[i];
	}
	for (int i = 0; i < m; ++i)
	{
		cin >> piekarnik;
		cout << solve(piekarnik) << endl;
	}
	return 0;
}