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 JavaScript (node.js v5.12) (judge verdict: Time Limit Exceeded)

"use strict";

function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }

function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }

function _iterableToArrayLimit(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }

function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }

function main(input) {
  var lines = input.split('\n');

  var _splitNum = splitNum(lines[0]),
      _splitNum2 = _slicedToArray(_splitNum, 2),
      N = _splitNum2[0],
      Q = _splitNum2[1];

  var A = splitNum(lines[1]).slice(0, N);
  var X = splitNum(lines.slice(2)).slice(0, Q);
  var cards = A.map(function (a, idx) {
    return {
      value: a,
      idx
    };
  }); // ranking by Takahashi

  cards.sort(function (x, y) {
    return y.value - x.value;
  });
  var _iteratorNormalCompletion = true;
  var _didIteratorError = false;
  var _iteratorError = undefined;

  try {
    var _loop = function _loop() {
      var x = _step.value;
      var taken = new Array(N).fill(false); // sort A by Aoki preference.

      var cvp = function cvp(card) {
        return Math.abs(card.value - x) + (card.value < x ? -0.1 : 0);
      };

      var mycards = cards.concat([]).sort(function (x, y) {
        return cvp(x) - cvp(y);
      }); // simulate the game.

      var sum = 0;
      var takahashi = 0;

      for (var i = 0; i < N; i++) {
        // Takahashi takes one
        for (; takahashi < N; takahashi++) {
          var c = cards[takahashi];

          if (!taken[c.idx]) {
            taken[c.idx] = true;
            sum += c.value;
            takahashi++;
            break;
          }
        }

        for (; i < N; i++) {
          var card = mycards[i];

          if (taken[card.idx]) {
            continue;
          }

          taken[card.idx] = true;
          break;
        }
      }

      console.log(sum);
    };

    for (var _iterator = X[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
      _loop();
    }
  } catch (err) {
    _didIteratorError = true;
    _iteratorError = err;
  } finally {
    try {
      if (!_iteratorNormalCompletion && _iterator.return != null) {
        _iterator.return();
      }
    } finally {
      if (_didIteratorError) {
        throw _iteratorError;
      }
    }
  }
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

function splitNum(line) {
  var arr = Array.isArray(line) ? line : line.split(/\s+/);
  return arr.map(function (n) {
    return parseInt(n);
  });
}