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
#include <bits/stdc++.h>
typedef long long ll;
#define F(i,a,b) for(ll i=a;i<=b;i++)
#define Fd(i,a,b) for(ll i=a;i>=b;i--)
using namespace std;
const int N=((1e6)+6);

ll wn[N];
vector< pair<ll, ll> > broom;

 int main()
 {
	ll n,m;
	scanf("%lld%lld",&n,&m);

	ll prv,x;
	prv=0;
	F(i,1,n)
	{
		scanf("%lld",&x);	
		broom.push_back(make_pair(x-prv,0));
		prv=x;
	}	

	F(i,1,m)
	{
		scanf("%lld",&x);
		broom.push_back(make_pair(x,i));
	}

	sort(broom.begin(),broom.end());

	ll blocks, res, T;
	res=0;
	blocks=n;
	T=0;
	for(auto z : broom)
	{
		res+=(z.first-T)*(n-blocks);
		T=z.first;
		wn[z.second]=res;

		if(z.second==0) blocks--;
	}

	F(i,1,m) printf("%lld\n",wn[i]);
 }