Problem:
Score : 400 points

Problem Statement

Takahashi is going to buy N items one by one.

The price of the i-th item he buys is A_i yen (the currency of Japan).

He has M discount tickets, and he can use any number of them when buying an item.

If Y tickets are used when buying an item priced X yen, he can get the item for \frac{X}{2^Y} (rounded down to the nearest integer) yen.

What is the minimum amount of money required to buy all the items?

Constraints

All values in input are integers.

1 \leq N, M \leq 10^5

1 \leq A_i \leq 10^9

Input

Input is given from Standard Input in the following format:

N M
A_1 A_2 ... A_N

Output

Print the minimum amount of money required to buy all the items.

Sample Input 1

3 3
2 13 8

Sample Output 1

9

We can buy all the items for 9 yen, as follows:

Buy the 1-st item for 2 yen without tickets.

Buy the 2-nd item for 3 yen with 2 tickets.

Buy the 3-rd item for 4 yen with 1 ticket.

Sample Input 2

4 4
1 9 3 5

Sample Output 2

6

Sample Input 3

1 100000
1000000000

Sample Output 3

0

We can buy the item priced 1000000000 yen for 0 yen with 100000 tickets.

Sample Input 4

10 1
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000

Sample Output 4

9500000000

Solution in Lua (Lua 5.3.5) (judge verdict: Accepted)

--url : https://devforum.roblox.com/t/commonly-used-tree-data-structures-in-lua/265673/2

----------

--[[
	Pairing Min Heap
	
	Binary Heap is faster for increasing and random pushes but this is faster for joining (merging) and decreasing pushes
	It is very optimized
	
	Use Kill to GC after finished using
	
--]]

--[[
	Node: {
	Key,
	LeftChild,
	NextSibling,
	}
	
--]]

-- Constants

-- cached variables

-- local variables

local tables={}
local tSize=0

local function merge(a,b)
	if not a then
		return b
	elseif not b then
		return a
	elseif a[1]<b[1]then
		-- inlined add child
		b[3]=a[2]
		a[2]=b
		
		return a
	else
		-- inlined add child
		a[3]=b[2]
		b[2]=a
		
		return b
	end
end

local function twopassmerge(a)
	local b=a and a[3]
	if b then
		local newnode=b[3]
		
		a[3]=false
		b[3]=false
		
		return merge(merge(a,b),twopassmerge(newnode))
	else
		return a
	end
end

local function empty(heap)
	return not heap.root
end

local function top(heap)
	return heap.root[1]
end

local function push(heap,key)
	local root=heap.Size+1
	heap.Size=root
	local t=heap.maxSize
	heap.maxSize=(root>t and root)or t
	
	-- inlined merge (optimized for insert)
	root=heap.root
	if not root then
		if tSize>0 then
			t=tables[tSize]
			tables[tSize]=nil
			tSize=tSize-1
			t[1]=key
			heap.root=t
		else
			heap.root={
				key,
				false,
				false,
			}
		end
	elseif root[1]<key then
		if tSize>0 then
			t=tables[tSize]
			tables[tSize]=nil
			tSize=tSize-1
			t[1]=key
			t[3]=root[2]
			root[2]=t
		else
			root[2]={
				key,
				false,
				root[2],
			}
		end
	else
		if tSize>0 then
			t=tables[tSize]
			tables[tSize]=nil
			tSize=tSize-1
			t[1]=key
			t[2]=root
			heap.root=t
		else
			heap.root={
				key,
				root,
				false,
			}
		end
	end
end

local function pop(heap)
	heap.Size=heap.Size-1
	local root=heap.root
	heap.root=twopassmerge(root[2])
	root[1]=false
	root[2]=false
	root[3]=false
	tSize=tSize+1
	tables[tSize]=root
end

local function join(heap1,heap2)
	-- assumes non empty heaps
	-- don't kill heap2 after merging
	
	local a=heap1.Size+heap2.Size
	heap1.Size=a
	local b=heap1.maxSize
	heap1.maxSize=(a>b and a)or b
	
	a=heap1.root
	b=heap2.root
	
	-- inlined merge
	if a[1]<b[1]then
		-- inlined add child
		b[3]=a[2]
		a[2]=b
	else
		-- inlined add child
		a[3]=b[2]
		b[2]=a
		
		heap1.root=b
	end
	
	return heap1
end

local function kill(heap)
	local nt=tSize-heap.maxSize+heap.Size
	for i=nt+1,tSize do
		tables[i]=nil
	end
	tSize=nt
end

local heap={
	empty=empty,
	top=top,
	push=push,
	pop=pop,
	join=join,
	kill=kill,
}

function heap.new(expectedspace)
	expectedspace=expectedspace or 0
	local nt=tSize+expectedspace
	for i=tSize+1,nt do
		tables[i]={false,false,false,}
	end
	tSize=nt
	
	return{
		empty=empty,
		top=top,
		push=push,
		pop=pop,
		join=join,
		kill=kill,
		
		Size=0,
		maxSize=expectedspace,
    }
end

----------

local n,m=io.read("n","n")
local a=heap.new(n)
for i=1,n do
    a:push(-io.read("n"))
end

for i=1,m do
    local x=-a:top()
    a:pop()
    a:push(-(x//2))
end

local total=0
for i=1,n do
    total=total-a:top()
    a:pop()
end
print(total)