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# (Mono 4.6.2.0) (judge verdict: Wrong Answer)

using System;
using System.Collections.Generic;
using System.Text;

public class Program
{
    private int N, Q;
    private int[] A;
    private int[] X;
    private Set<int> Set;
    private long[] Sum, SumOdd, SumEven;

    public void Solve()
    {
        var sc = new Scanner();
        N = sc.NextInt();
        Q = sc.NextInt();
        A = sc.IntArray();
        X = new int[Q];
        for (int i = 0; i < Q; i++)
        {
            X[i] = sc.NextInt();
        }

        Set = new Set<int>();
        foreach (int i in A)
        {
            Set.Add(i);
        }

        Sum = new long[N + 1];
        SumEven = new long[(N + 1) / 2 + 1];
        SumOdd = new long[N / 2 + 1];

        for (int i = 0; i < N; i++)
        {
            Sum[i + 1] = Sum[i] + A[i];
            if (i % 2 == 0)
            {
                SumEven[i / 2 + 1] = SumEven[i / 2] + A[i];
            }
            else
            {
                SumOdd[i / 2 + 1] = SumOdd[i / 2] + A[i];
            }
        }

        var sb = new StringBuilder();
        foreach (int x in X)
        {
            sb.AppendLine(Query(x).ToString());
        }

        Console.Write(sb.ToString());
    }

    private long Query(int x)
    {
        if (A[N - 1] <= x)
        {
            if (N % 2 == 0)
            {
                return SumOdd[N / 2];
            }
            else
            {
                return SumEven[N / 2 + 1];
            }
        }

        int min = Set.LowerBound(x);

        int max = N;
        if (min + 1 - Set.LowerBound(2 * x - A[min]) >= N - min)
        {
            max = min;
            min--;
        }
        else
        {
            while (max - min > 1)
            {
                int med = (max + min) / 2;
                // 相手がいなかった時A[med]を何番目に取るか t 高橋くん a 青木くん
                int t = N - med;
                int l = Set.LowerBound(2 * x - A[med]);
                int a = med - l + 1;
                if (a < t)
                    min = med;
                else
                    max = med;
            }
        }

        //Console.WriteLine($"d {N - min} {min + 1 - Set.LowerBound(2 * x - A[min])}");


        // [max,N)は高橋くん
        // [ll,min]は青木くん
        int ll = A[min] < x ? min : Set.LowerBound(2 * x - A[min]);

        long takahashi = 0;
        takahashi += Sum[N] - Sum[max];

        //Console.WriteLine($"aaaa {takahashi} {min} {ll}");
        if (N % 2 == 1)
        {
            takahashi += SumEven[(ll + 1) / 2];
        }
        else
        {
            takahashi += SumOdd[ll / 2];
        }

        return takahashi;
    }


    public static void Main(string[] args)
    {
        new Program().Solve();
    }
}

#region Set

public class Set<T>
{
    Node root;
    readonly IComparer<T> comparer;
    readonly Node nil;
    public bool IsMultiSet { get; set; }

    public Set(IComparer<T> comparer)
    {
        nil = new Node(default(T));
        root = nil;
        this.comparer = comparer;
    }

    public Set(Comparison<T> comaprison) : this(Comparer<T>.Create(comaprison))
    {
    }

    public Set() : this(Comparer<T>.Default)
    {
    }

    public bool Add(T v)
    {
        return insert(ref root, v);
    }

    public bool Remove(T v)
    {
        return remove(ref root, v);
    }

    public T this[int index]
    {
        get { return find(root, index); }
    }

    public int Count
    {
        get { return root.Count; }
    }

    public void RemoveAt(int k)
    {
        if (k < 0 || k >= root.Count) throw new ArgumentOutOfRangeException();
        removeAt(ref root, k);
    }

    public T[] Items
    {
        get
        {
            var ret = new T[root.Count];
            var k = 0;
            walk(root, ret, ref k);
            return ret;
        }
    }

    void walk(Node t, T[] a, ref int k)
    {
        if (t.Count == 0) return;
        walk(t.lst, a, ref k);
        a[k++] = t.Key;
        walk(t.rst, a, ref k);
    }

    bool insert(ref Node t, T key)
    {
        if (t.Count == 0)
        {
            t = new Node(key);
            t.lst = t.rst = nil;
            t.Update();
            return true;
        }

        var cmp = comparer.Compare(t.Key, key);
        bool res;
        if (cmp > 0)
            res = insert(ref t.lst, key);
        else if (cmp == 0)
        {
            if (IsMultiSet) res = insert(ref t.lst, key);
            else return false;
        }
        else res = insert(ref t.rst, key);

        balance(ref t);
        return res;
    }

    bool remove(ref Node t, T key)
    {
        if (t.Count == 0) return false;
        var cmp = comparer.Compare(key, t.Key);
        bool ret;
        if (cmp < 0) ret = remove(ref t.lst, key);
        else if (cmp > 0) ret = remove(ref t.rst, key);
        else
        {
            ret = true;
            var k = t.lst.Count;
            if (k == 0)
            {
                t = t.rst;
                return true;
            }

            if (t.rst.Count == 0)
            {
                t = t.lst;
                return true;
            }


            t.Key = find(t.lst, k - 1);
            removeAt(ref t.lst, k - 1);
        }

        balance(ref t);
        return ret;
    }

    void removeAt(ref Node t, int k)
    {
        var cnt = t.lst.Count;
        if (cnt < k) removeAt(ref t.rst, k - cnt - 1);
        else if (cnt > k) removeAt(ref t.lst, k);
        else
        {
            if (cnt == 0)
            {
                t = t.rst;
                return;
            }

            if (t.rst.Count == 0)
            {
                t = t.lst;
                return;
            }

            t.Key = find(t.lst, k - 1);
            removeAt(ref t.lst, k - 1);
        }

        balance(ref t);
    }

    void balance(ref Node t)
    {
        var balance = t.lst.Height - t.rst.Height;
        if (balance == -2)
        {
            if (t.rst.lst.Height - t.rst.rst.Height > 0)
            {
                rotR(ref t.rst);
            }

            rotL(ref t);
        }
        else if (balance == 2)
        {
            if (t.lst.lst.Height - t.lst.rst.Height < 0) rotL(ref t.lst);
            rotR(ref t);
        }
        else t.Update();
    }

    T find(Node t, int k)
    {
        if (k < 0 || k > root.Count) throw new ArgumentOutOfRangeException();
        for (;;)
        {
            if (k == t.lst.Count) return t.Key;
            else if (k < t.lst.Count) t = t.lst;
            else
            {
                k -= t.lst.Count + 1;
                t = t.rst;
            }
        }
    }

    public int LowerBound(T v)
    {
        var k = 0;
        var t = root;
        for (;;)
        {
            if (t.Count == 0) return k;
            if (comparer.Compare(v, t.Key) <= 0) t = t.lst;
            else
            {
                k += t.lst.Count + 1;
                t = t.rst;
            }
        }
    }

    public int UpperBound(T v)
    {
        var k = 0;
        var t = root;
        for (;;)
        {
            if (t.Count == 0) return k;
            if (comparer.Compare(t.Key, v) <= 0)
            {
                k += t.lst.Count + 1;
                t = t.rst;
            }
            else t = t.lst;
        }
    }

    void rotR(ref Node t)
    {
        var l = t.lst;
        t.lst = l.rst;
        l.rst = t;
        t.Update();
        l.Update();
        t = l;
    }

    void rotL(ref Node t)
    {
        var r = t.rst;
        t.rst = r.lst;
        r.lst = t;
        t.Update();
        r.Update();
        t = r;
    }


    class Node
    {
        public Node(T key)
        {
            Key = key;
        }

        public int Count { get; private set; }
        public sbyte Height { get; private set; }
        public T Key { get; set; }
        public Node lst, rst;

        public void Update()
        {
            Count = 1 + lst.Count + rst.Count;
            Height = (sbyte) (1 + Math.Max(lst.Height, rst.Height));
        }

        public override string ToString()
        {
            return string.Format("Count = {0}, Key = {1}", Count, Key);
        }
    }
}

#endregion

class Scanner
{
    public Scanner()
    {
        _pos = 0;
        _line = new string[0];
    }

    const char Separator = ' ';
    private int _pos;
    private string[] _line;

    #region スペース区切りで取得

    public string Next()
    {
        if (_pos >= _line.Length)
        {
            _line = Console.ReadLine().Split(Separator);
            _pos = 0;
        }

        return _line[_pos++];
    }

    public int NextInt()
    {
        return int.Parse(Next());
    }

    public long NextLong()
    {
        return long.Parse(Next());
    }

    public double NextDouble()
    {
        return double.Parse(Next());
    }

    #endregion

    #region 型変換

    private int[] ToIntArray(string[] array)
    {
        var result = new int[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = int.Parse(array[i]);
        }

        return result;
    }

    private long[] ToLongArray(string[] array)
    {
        var result = new long[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = long.Parse(array[i]);
        }

        return result;
    }

    private double[] ToDoubleArray(string[] array)
    {
        var result = new double[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = double.Parse(array[i]);
        }

        return result;
    }

    #endregion

    #region 配列取得

    public string[] Array()
    {
        if (_pos >= _line.Length)
            _line = Console.ReadLine().Split(Separator);

        _pos = _line.Length;
        return _line;
    }

    public int[] IntArray()
    {
        return ToIntArray(Array());
    }

    public long[] LongArray()
    {
        return ToLongArray(Array());
    }

    public double[] DoubleArray()
    {
        return ToDoubleArray(Array());
    }

    #endregion
}