Problem:
Score : 500 points

Problem Statement

There are N cards. The i-th card has an integer A_i written on it.
For any two cards, the integers on those cards are different.

Using these cards, Takahashi and Aoki will play the following game:

Aoki chooses an integer x.

Starting from Takahashi, the two players alternately take a card. The card should be chosen in the following manner:

Takahashi should take the card with the largest integer among the remaining card.

Aoki should take the card with the integer closest to x among the remaining card. If there are multiple such cards, he should take the card with the smallest integer among those cards.

The game ends when there is no card remaining.

You are given Q candidates for the value of x: X_1, X_2, ..., X_Q.
For each i (1 \leq i \leq Q), find the sum of the integers written on the cards that Takahashi will take if Aoki chooses x = X_i.

Constraints

2 \leq N \leq 100 000

1 \leq Q \leq 100 000

1 \leq A_1 < A_2 < ... < A_N \leq 10^9

1 \leq X_i \leq 10^9 (1 \leq i \leq Q)

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N Q
A_1 A_2 ... A_N
X_1
X_2
:
X_Q

Output

Print Q lines. The i-th line (1 \leq i \leq Q) should contain the answer for x = X_i.

Sample Input 1

5 5
3 5 7 11 13
1
4
9
10
13

Sample Output 1

31
31
27
23
23

For example, when x = X_3(= 9), the game proceeds as follows:

Takahashi takes the card with 13.

Aoki takes the card with 7.

Takahashi takes the card with 11.

Aoki takes the card with 5.

Takahashi takes the card with 3.

Thus, 13 + 11 + 3 = 27 should be printed on the third line.

Sample Input 2

4 3
10 20 30 40
2
34
34

Sample Output 2

70
60
60

Solution in C (GCC 5.4.1) (judge verdict: Runtime Error)


#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>

#define ll long long
#define fr(i,l,r) for(i=(l);i<(r);i++)
#define min(p,q) ((p)<(q)?(p):(q))
#define max(p,q) ((p)>(q)?(p):(q))
#define INF 1000000000000//10^12


struct query_t {
	ll int idnum;
	ll int x;
	ll int ans;
};


int compare_x(const void *a, const void *b) {
	struct query_t *A = (struct query_t *)a;
	struct query_t *B = (struct query_t *)b;
	return A->x - B->x;
}

int compare_idnum(const void *a, const void *b) {
	struct query_t *A = (struct query_t *)a;
	struct query_t *B = (struct query_t *)b;
	return A->idnum - B->idnum;
}


int main(void)
{
	//変数の宣言
	ll int n, q;
	static ll int a[100010];
	static struct query_t query[100010];
	static ll int ruiseki[100010];
	static ll int odd[100010];
	static ll int even[100010];
	static ll int memo[100010];
	static ll int l, r;

	//よく使う変数
	ll int i, j, k;
	ll int flag = 0;
	//	ll int ans=0;
	ll int count = 0;
	ll int temp, temp1, temp2;
	ll int max, min;
	ll int len;
	ll int sum = 0;

	//データの読み込み

	scanf("%lld %lld", &n, &q);
//	scanf_s("%lld %lld", &n, &q);



	for (i = 0;i < n;i++) {
		scanf("%lld", &a[i]);
//		scanf_s("%lld", &a[i]);
	}

	for (i = 0;i < q;i++) {
		scanf("%lld", &query[i].x);
//		scanf_s("%lld", &query[i].x);
		query[i].idnum = i;
		query[i].ans = 0;
	}

	//	printf("nは%dです\n", n);
	//	printf("データの読み込み終了\n");
		//実際の処理

	for (i = 0;i < n;i++) {
		if (i == 0) {
			ruiseki[0] = a[0];
			even[0] = a[0];
			odd[0] = 0;
		}
		else {
			ruiseki[i] = ruiseki[i - 1] + a[i];
			if (i % 2 == 0) {
				even[i] = even[i - 2] + a[i];
				odd[i] = 0;
			}
			else {
				odd[i] = odd[i - 2] + a[i];
				even[i] = 0;
			}
		}
	}

	qsort(query, q, sizeof(struct query_t), compare_x);


	r = 0;
	while (a[r] < query[0].x&&r < n - 1) {
		r++;
	}
	l = r;
	if (r < n - 2) {
		flag = 0;
	}
	else {
		flag = 1;
	}

	while (flag==0) {
		if (l!=0 && abs(query[0].x - a[l - 1]) < abs(query[0].x - a[r + 1])) {
			l = l - 1;
			if (r - l + 1 < n - r - 1) {
				flag = 0;
			}
			else {
				flag = 1;
			}
		}
		else {
			r = r + 1;
			if (r - l + 1 == n - r - 1) {
				flag = 1;
			}
			else if(r-l+1>n-r-1) {
				flag = 1;
				r--;
			}
			else {
				flag = 0;
			}
		}
	}
	printf("x=%lld l=%lld r=%lld\n", query[0].x, l, r);

	if (r == n - 1) {
		query[0].ans = even[n - 1] + odd[n - 1];
	}
	else {
		query[0].ans = ruiseki[n - 1] - ruiseki[r];

		if ((n - l) % 2 == 0) {
			if (l > 0) query[0].ans = query[0].ans + even[l - 1] + odd[l - 1];
		}
		else {
			if (l > 1) query[0].ans = query[0].ans + even[l - 2] + odd[l - 2];
		}
	}


	for (i = 1;i < q;i++) {
		if (a[r] < query[i].x) {
			while (a[r] < query[i].x) {
				r++;
			}
			if (abs(query[i].x - a[r - 1]) <= abs(query[i].x - a[r])) {
				r--;
			}
			l = r;
		}
		else {
			while (abs(query[i].x - a[l]) < abs(query[i].x - a[r])) {
				l = l + 1;
			}
		}
		flag = 0;
		while (flag == 0) {
			if (l!=0 && abs(query[i].x - a[l - 1]) < abs(query[i].x - a[r + 1])) {
				l = l - 1;
				if (r - l + 1 < n - r - 1) {
					flag = 0;
				}
				else {
					flag = 1;
				}
			}
			else {
				r = r + 1;
				if (r - l + 1 == n - r - 1) {
					flag = 1;
				}
				else if (r - l + 1 > n - r - 1) {
					flag = 1;
					r--;
				}
				else {
					flag = 0;
				}
			}
		}
		printf("x=%lld l=%lld r=%lld\n",query[i].x, l, r);
		if (r == n - 1) {
			query[i].ans = even[n - 1] + odd[n - 1];
		}
		else {
			query[i].ans = ruiseki[n - 1] - ruiseki[r];

			if ((n - l) % 2 == 0) {
				if (l > 0) query[i].ans = query[i].ans + even[l - 1] + odd[l - 1];
			}
			else {
				if (l > 1) query[i].ans = query[i].ans + even[l - 2] + odd[l - 2];
			}
		}
	}

	qsort(query, q, sizeof(struct query_t), compare_idnum);

	//	printf("計算部分終了\n");

		//出力
	for (i = 0;i < q;i++) {
		printf("%lld\n", query[i].ans);
	}
	//	printf("結果の出力終了\n");

	return 0;
}