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: Wrong Answer)

#include <float.h>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

// 内部定数
#define D_CARD_MAX		100000									// 最大カード数
#define D_RATE			10										// 倍率

// 内部変数
static FILE *szpFpI;											// 入力
static long long sl1Card[D_CARD_MAX];							// カード
static int siCCnt;												// カード数
static long long sl1Sum[D_CARD_MAX];							// カード累計
static long long sl1Sum2[D_CARD_MAX];							// カード累計(交互)
static long long slX;											// X

// 内部変数 - テスト用
#ifdef D_TEST
	static int siRes;
	static FILE *szpFpA;
	static int siTNo;
#endif

// １行出力
int
fOutLine(
	char *pcpLine				// <I> １行
)
{
	char lc1Buf[1024];

#ifdef D_TEST
	lc1Buf[0] = '\0';
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, pcpLine)) {
		siRes = -1;
	}
#else
	printf("%s", pcpLine);
#endif

	return 0;
}

// 距離 - 取得
long long
fGetLen(
	int piCnt					// <I> 連続枚数
	, int piSNo					// <I> 開始位置
	, int *pipBest				// <O> 最適位置
	, long long *plpBestLen		// <O> 最適距離
)
{
	// 距離 - 取得
	long long llLen = abs(slX - sl1Card[piSNo]);
	long long llLen2 = abs(slX - sl1Card[piSNo + piCnt - 1]);
	if (llLen < llLen2) {
		llLen = llLen2;
	}

	// 最適 - 更新
	if (*plpBestLen > llLen) {
		*plpBestLen = llLen;
		*pipBest = piSNo;
	}

	return llLen;
}

// 連続枚数 - 判定
int
fChkCnt(
	int piCnt					// <I> 連続枚数
	, int *pipSNo				// <O> 開始位置
)
{
	// 開始位置 - 取得
	int liBest;
	long long llBestLen = LLONG_MAX;
	int liMin = 0;
	int liMax = siCCnt - 1 - piCnt;
	fGetLen(piCnt, liMin, &liBest, &llBestLen);
	fGetLen(piCnt, liMax, &liBest, &llBestLen);
	while (liMin + 1 < liMax) {

		// 間隔
		int liSep = (liMax - liMin) / 3;
		if (liSep < 1) {
			liSep = 1;
		}

		// 距離 - 取得
		int liMin2 = liMin + liSep;
		int liMax2 = liMax - liSep;
		long long llMinLen2 = fGetLen(piCnt, liMin2, &liBest, &llBestLen);
		long long llMaxLen2 = fGetLen(piCnt, liMax2, &liBest, &llBestLen);
		if (llMinLen2 < llMaxLen2) {
			liMax = liMax2;
		}
		else {
			liMin = liMin2;
		}
	}

	// 重複あり
	if (liBest + piCnt - 1 >= siCCnt - piCnt) {
		return -1;
	}

	// 開始位置
	*pipSNo = liBest;

	return 0;
}

// 連続枚数 - 取得
int
fGetCnt(
	int *pipSNo					// <O> 開始位置
)
{
	int liRet;

	// 範囲を絞る
	int liMin = 0;
	int liMax = siCCnt / 2;
	int liCnt = 0;
	while (liMin <= liMax) {
		int liAvg = (liMin + liMax) / 2;
		liRet = fChkCnt(liAvg, pipSNo);
		if (liRet == 0) {
			liMin = liAvg + 1;
			liCnt = liAvg;
		}
		else {
			liMax = liAvg - 1;
		}
	}

	return liCnt;
}

// 実行メイン
int
fMain(
)
{
	int i;
	char lc1Buf[1024];

	// カード数・クエリ数 - 取得
	int liQCnt;
	fgets(lc1Buf, sizeof(lc1Buf), szpFpI);
	sscanf(lc1Buf, "%d%d", &siCCnt, &liQCnt);

	// カード - 取得
	for (i = 0; i < siCCnt; i++) {
		fscanf(szpFpI, "%lld", &sl1Card[i]);
		sl1Card[i] *= D_RATE;
	}
	fgets(lc1Buf, sizeof(lc1Buf), szpFpI);

	// カード累計 - セット
	sl1Sum[0] = sl1Card[0];
	for (i = 1; i < siCCnt; i++) {
		sl1Sum[i] = sl1Sum[i - 1] + sl1Card[i];
	}

	// カード累計(交互) - セット
	sl1Sum2[0] = sl1Card[0];
	for (i = 2; i < siCCnt; i+=2) {
		sl1Sum2[i] = sl1Sum2[i - 2] + sl1Card[i];
	}
	sl1Sum2[1] = sl1Card[1];
	for (i = 3; i < siCCnt; i+=2) {
		sl1Sum2[i] = sl1Sum2[i - 2] + sl1Card[i];
	}

	// クエリ - 取得
	for (i = 0; i < liQCnt; i++) {
		fgets(lc1Buf, sizeof(lc1Buf), szpFpI);
		sscanf(lc1Buf, "%lld", &slX);
		slX = slX * D_RATE - 1;
		long long llSum = 0;
		int liENo = liQCnt - 1;

		// 連続枚数
		int liANo;
		int liCnt = fGetCnt(&liANo);
		if (liCnt > 0) {
			int liTNo = siCCnt - liCnt - 1;
			llSum += sl1Sum[siCCnt - 1] - sl1Sum[liTNo];
			liENo = liANo - 1;

			// 隙間
			if (liANo + liCnt - 1 < liTNo) {
				llSum += sl1Card[liTNo];
				liENo--;
			}
		}

		// 交互枚数
		if (liENo >= 0) {
			llSum += sl1Sum2[liENo];
		}

		// 出力
		sprintf(lc1Buf, "%lld\n", llSum / D_RATE);
		fOutLine(lc1Buf);
	}

	return 0;
}

// １回実行
int
fOne(
)
{
	int liRet;
	char lc1Buf[1024];

	// 入力 - セット
#ifdef D_TEST
	sprintf(lc1Buf, ".\\Test\\T%d.txt", siTNo);
	szpFpI = fopen(lc1Buf, "r");
	sprintf(lc1Buf, ".\\Test\\A%d.txt", siTNo);
	szpFpA = fopen(lc1Buf, "r");
	siRes = 0;
#else
	szpFpI = stdin;
#endif

	// 実行メイン
	liRet = fMain();

	// 残データ有無
#ifdef D_TEST
	lc1Buf[0] = '\0';
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, "")) {
		siRes = -1;
	}
#endif

	// テストファイルクローズ
#ifdef D_TEST
	fclose(szpFpI);
	fclose(szpFpA);
#endif

	// テスト結果
#ifdef D_TEST
	if (siRes == 0) {
		printf("OK %d\n", siTNo);
	}
	else {
		printf("NG %d\n", siTNo);
	}
#endif

	return 0;
}

// プログラム開始
int
main()
{

#ifdef D_TEST
	int i;
	for (i = D_TEST_SNO; i <= D_TEST_ENO; i++) {
		siTNo = i;
		fOne();
	}
#else
	fOne();
#endif

	return 0;
}