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
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#include <bits/stdc++.h>
#define int long long
#define st first
#define nd second
#define mp(a, b) make_pair(a, b)
#define pb push_back
#define mt make_tuple
#define e(a, b) get<b>(a)
using namespace std;
struct piec{
	int l, poz, wyn;
};
piec tbl[1002000];
bool f(const piec &a, const piec &b)
{
	return a.l<b.l;
}
bool h(const piec &a, const piec &b)
{
	return a.poz<b.poz;
}
struct event{
	int l;
	int p;
	long double t;
	event (int a, int b, long double c)
	{
		l=a;
		p=b;
		t=c;
	}
};
struct comp{
	bool operator ()(const event &a, const event &b)
	{
		if (a.t<b.t)
			return true;
		if (a.t>b.t)
			return false;
		return a.l>b.l;
	}
};
set<event, comp> s;
int t[1002000];
int nast[1002000], /*poprz[1000200], */ile[1020000];
int32_t main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, m;
	int lin=0, cons=0;
	cin>>n>>m;
	ile[0]=1;
	nast[0]=1;
	for (int i=1; i<=n; i++)
	{
		cin>>t[i];
		//cons-=t[i];
		ile[i]=1;
		nast[i]=i+1;
		//poprz[i]=i-1;
	}
	n++;
	for (int i=0; i<m; i++)
	{
		cin>>tbl[i].l;
		tbl[i].poz=i;
	}
	sort(tbl, tbl+m, f);
	for (int i=1; i<n; i++)
	{
		s.insert(*(new event(i-1, i, t[i]-t[i-1])));
	}
	
			/*for (auto it : s)
			{
				cout<<it.l<<","<<it.p<<","<<it.t<<"\t";
			}
			cout<<"\n";*/
			
	for (int i=0; i<m; i++)
	{//cout<<"UU\n";
		while(s.size() && s.begin()->t<=tbl[i].l)
		{
	//cout<<"eh ";
			auto q=*(s.begin());
			s.erase(s.begin());
			int codalej=nast[q.p];
			if (codalej!=n)
			{
				s.erase(*(new event(q.p, codalej, (t[codalej]-t[q.p])/(1.0*ile[q.p]))));
			}
			/*for (auto it : s)
			{
				cout<<it.l<<","<<it.p<<","<<it.t<<"\t";
			}
			cout<<"\n";
			cout<<(q).p<<" "<<(q).l<<"\n";*/
			cons-=(t[q.p]-t[q.l])*ile[q.p];
			lin-=ile[q.p]*(ile[q.p]-1)/2;
			lin-=ile[q.l]*(ile[q.l]-1)/2;
			ile[q.l]+=ile[q.p];
			nast[q.l]=nast[q.p];
			//poprz[nast[q.p]]=q.l;
			if (nast[q.l]!=n)
			{
				s.insert(*(new event(q.l, nast[q.l], (t[nast[q.l]]-t[q.l])/(1.0*ile[q.l]))));
			}
			lin+=ile[q.l]*(ile[q.l]-1)/2;
			/*for (auto it : s)
			{
				cout<<it.l<<","<<it.p<<","<<it.t<<"\t";
			}
			cout<<"\n";
			system("pause");*/
		}
		//cout<<"AA\n";
		tbl[i].wyn=cons+lin*tbl[i].l;
	}
	sort(tbl, tbl+m, h);
	for (int i=0; i<m; i++)
	{
		cout<<tbl[i].wyn<<"\n";
	}
	return 0;
}