parameters = gets.to_s
numOfCard = parameters.split(" ")[0].to_i
numOfGames = parameters.split(" ")[1].to_i

cardsString = gets.to_s

arrayOfCardsOriginal = []

for card in 0..numOfCard-1 do
    arrayOfCardsOriginal << cardsString.split(" ")[card].to_i
end

startNumber = []

for times in 0..numOfGames-1 do
    startNumber << gets.to_i
end
arrayOfCardsOriginal.sort!


for game in 0..numOfGames-1 do

    arrayOfCards = []
    arrayOfCards = Marshal.load(Marshal.dump(arrayOfCardsOriginal))

    takahashi = []

    while arrayOfCards.size != 0 do
        takahashi << arrayOfCards.max
        arrayOfCards.delete(arrayOfCards.max) 

        if arrayOfCards.size != 0 then
            ##arrayOFCardsをしたから順に一個づつ見ていき、初めてxを超えたカード一つ下のカード
            if  arrayOfCards.max  < startNumber[game] then
                arrayOfCards.delete(arrayOfCards.max)
            elsif arrayOfCards.min > startNumber[game] then
                arrayOfCards.delete(arrayOfCards.min)
            else
                for times in 0..numOfCard-1 do
                    if arrayOfCards[times] > startNumber[game] then
                        if startNumber[game] - arrayOfCards[times-1] < arrayOfCards[times] - startNumber[game] then
                            arrayOfCards.delete(arrayOfCards[times-1])
                            break
                        elsif startNumber[game] - arrayOfCards[times-1] > arrayOfCards[times] - startNumber[game] then
                            arrayOfCards.delete(arrayOfCards[times])
                            break
                        elsif startNumber[game] - arrayOfCards[times-1] == arrayOfCards[times] - startNumber[game] then
                            arrayOfCards.delete(arrayOfCards[times-1])
                            break
                        end
                    end
                end
            end
        end
    end

    puts takahashi.inject(:+)

end
