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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>

using uint64 = unsigned long long;
using uint32 = unsigned int;

using ClientT = std::vector < uint64 > ;
using OvensT = std::vector < uint32 > ;

void ScanInput( ClientT& Clients, OvensT& Ovens )
{
	uint64 N;
	uint64 M;
	std::cin >> N;
	std::cin >> M;
	Clients.resize(N);
	Ovens.resize(M);

	for (auto i = 0; i < N; ++i)
	{
		std::cin >> Clients[i];
	}
	for (auto i = 0; i < M; ++i)
	{
		std::cin >> Ovens[i];
	}
}


uint64 ComputePerOven(const ClientT& Clients, const uint32 capacity)
{
	uint64 ans{ 0 };
	uint64 pos{ 0 };
	for (const auto& client : Clients )
	{
		pos += capacity;
		pos = std::max(pos, client);
		ans += pos - client;
	}
	return ans;
}

void Compute(const ClientT& Clients, const OvensT& Ovens)
{
	for (const auto& oven : Ovens)
	{
		std::cout << ComputePerOven(Clients, oven) << std::endl;
	}
}

int main()
{
	std::ios_base::sync_with_stdio(false);

	ClientT Clients;
	OvensT Ovens;
	ScanInput(Clients, Ovens);
	Compute(Clients, Ovens);


	return 0;
}