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++14 (GCC 5.4.1) (judge verdict: Runtime Error)

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 0
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 100010

template< typename T >
class CumulativeSum
{
public:
    CumulativeSum() {}
    CumulativeSum(int sz) : m_Data(sz, T(0)) {};

    void Init(int sz) { m_Data.assign(sz, T(0)); }

    // k に x を加える O(1)
    void Add(int k, T x) {
        assert(static_cast<int>(m_Data.size()) >= k);
        if(static_cast<int>(m_Data.size()) <= k) { m_Data.push_back(x); }
        else { m_Data[k] = (m_Data[k] + x); }
    }

    // 累積和の構築 O(m_Data.size())
    void Build() {
        for(int i = 1; i < static_cast<int>(m_Data.size()); i++) {
            m_Data[i] = (m_Data[i] + m_Data[i - 1]);
        }
    }

    // 区間 [0, k] の和を返す O(1)
    // 閉区間なので k が含まれることに注意
    T Query(int k) {
        if(k < 0) { return T(0); }
        return (m_Data[min(k, static_cast<int>(m_Data.size()) - 1)]);
    }

    // 区間 [l, h] の和を返す O(1)
    // 閉区間なので k が含まれることに注意
    T Query(int l, int h) {
        return (this->Query(h) - this->Query(l-1));
    }
private:
    vector< T > m_Data;
};

// v の [lb, ub) の範囲に val があるか探す
// あるならそのインデックスを返す。なければ -1 を返す
// 同じ数が複数ある場合どのインデックスを返すかは不定
// ほかの bin_search を使って範囲を絞ること
static inline ll bin_search1(const vector<ll>& v, ll lb, ll ub, ll val) {
    while(lb < ub) {
        ll mid = (lb + ub) / 2;
        if(v[mid] == val) { return mid; }
        else if(val < v[mid]) { ub = mid; }
        else { lb = mid + 1; }
    }
    return -1;
}
// v の [lb, ub) の範囲で val 以上の要素が初めて出てくるインデックスを返す
// なければ -1 を返す
// -1 を返すとこ以外 std::lower_bound と同じ
// 同じ数が複数ある場合は一番小さいインデックスを返す
static inline ll bin_search2(const vector<ll>& v, ll lb, ll ub, ll val) {
    lb--; ub--;
    while(ub - lb > 1) {
        ll mid = (lb + ub) / 2;
        if(v[mid] >= val) { ub = mid; }
        else { lb = mid; }
    }
    // この時点で lb + 1 = ub
    return (v[ub] >= val) ? ub : -1;
}
// [lb, ub) の範囲で val 以下の要素で最大のもののインデックスを返す
// なければ -1 を返す
// 同じ数が複数ある場合は一番小さいインデックスを返す
static inline ll bin_search4(const vector<ll>& v, ll lb, ll ub, ll val) {
    lb--; ub--;
    while(ub - lb > 1) {
        ll mid = (lb + ub) / 2;
        if(v[mid] >= val) { ub = mid; }
        else { lb = mid; }
    }
    // この時点で lb + 1 = ub
    if(v[ub] <= val) { return ub; }
    if(lb < 0 || v[lb] > val) { return -1; }
    return lb;
}

ll N, Q;
vector<ll> A, X;
CumulativeSum<ll> cs_all, cs_odd, cs_even;

enum Player { Alice = 0, Bob = 1};  // Alice = Takahashi

// i 以降のカードが余っていて、次は player の手番の場合の
// Alice の取り分の合計
ll post(ll i, ll player) {
    if(i < 0) { return 0; }
    if(i % 2 == 0) {
        if(player == Alice) { return cs_even.Query(i); }
        else { return cs_odd.Query(i); }
    }
    else {
        if(player == Alice) { return cs_odd.Query(i); }
        else { return cs_even.Query(i); }
    }
}

enum Result { Ok = 0, BigAlice = 1, BigBob = 2};

// [lb, rb] の範囲でとれるカードの枚数を返す
ll get_cnt(ll lb, ll rb) {
    ll ind_l = bin_search2(A, 0, A.size(), lb);
    ll ind_r = bin_search4(A, 0, A.size(), rb);
    if(ind_l == -1 || ind_r == -1) { return 0; }
    return ind_r - ind_l + 1;
}

// X = x で半径 r の時に Alice と Bob が取れるカードの枚数を返す
pair<ll, ll> get_card(ll x, ll r) {
    ll b_card = get_cnt(x - r, x + r);
    ll a_card = get_cnt(x + r + 1, LLINF);

    // Bob の半径の両端にカードがあり、かつ、
    // Alice の左端もそのカードの場合は、 Alice に一枚渡す
    bool cond1 = (bin_search1(A, 0, A.size(), x - r) != -1);
    bool cond2 = (bin_search1(A, 0, A.size(), x + r) == N - a_card - 1);
    DBG("    cond1: %s cond2: %s\n", cond1 ? "true" : "false", cond2 ? "true" : "false");
    if(cond1 && cond2 && b_card == a_card + 1) {
        b_card--;
        a_card++;
    }

    // 取れるカードが最大のもの 1 枚の場合も Alice に渡す
    if(b_card == 1 && a_card == 0) {
        swap(a_card, b_card);
    }

    return make_pair(a_card, b_card);
}

// X = x の時に Bob が 半径 r 内のカードを取った場合に、
// Alice と Bob が取れるカードの枚数が同じにできるか
// Alice が 1 つ多く取れるなら Ok
// Alice が 2 つ以上多く取ってしまっているなら BigAlice
// Bob が多く取ってしまっているなら BigBob を返す
ll check(ll x, ll r) {
    pair<ll, ll> tmp = get_card(x, r);
    ll a_card = tmp.first;
    ll b_card = tmp.second;
    DBG("  r: %lld a_card: %lld b_card: %lld\n", r, a_card, b_card);
    if(a_card == b_card || a_card == b_card + 1) { return Ok; }
    else if(a_card > b_card + 1) { return BigAlice; }
    return BigBob;
}

// x の時に Alice がとるカードの数を返す
ll bin_search(ll x) {
    ll lb = 0, ub = 1000000000;
    while(ub - lb > 1) {
        // Bob がとる範囲
        ll mid = (lb + ub) / 2;
        ll result = check(x, mid);
        if(result == Ok) { return get_card(x, mid).first; }
        else if(result == BigBob) { ub = mid; }
        else { lb = mid; }
    }
    if(check(lb, x) == Ok) {
        return get_card(x, lb).first;
    }
    if(check(ub, x) == Ok) {
        return get_card(x, ub).first;
    }
    assert(false);
    return 0;
}

ll solve(ll x) {
    ll ret = 0;
    DBG("x: %lld\n", x);
    // Alice が右端からいくつ取ったところで Bob の取る領域とぶつかるかを求める
    ll a_card = bin_search(x);
    ret += cs_all.Query(N - a_card, N - 1);
    ret += post(N - (a_card * 2) - 1, Alice);
    return ret;
}

signed main()
{
    cin >> N >> Q;
    A.assign(N, 0);
    X.assign(Q, 0);
    cs_all.Init(N);
    cs_even.Init(N);
    cs_odd.Init(N);
    REP(i, N) {
        cin >> A[i];
        cs_all.Add(i, A[i]);
        if(i % 2 == 0) { cs_even.Add(i, A[i]); }
        else { cs_odd.Add(i, A[i]); }
    }
    REP(i, Q) { cin >> X[i]; }

    cs_all.Build();
    cs_even.Build();
    cs_odd.Build();

    REP(i, Q) {
        ll ans = solve(X[i]);
        printf("%lld\n", ans);
    }
    return 0;
}