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



Sample input:
3 3
2 13 8


Sample output:
9

Submission status: Runtime Error

Solution code:
import math

n, m = map(int, input().split())
item_price = list(map(int, input().split()))
# n, m = (4, 4)
# item_price = [1, 9, 3, 5]
item_price.sort(reverse=True)
devided_two_price = [math.ceil(math.log2(i)) for i in item_price]
use_ticket_list = [0] * n
sum = 0

x = 0
a = 2
for i in range(m):
    if devided_two_price[x] == a:
        x += 1
        use_ticket_list[x] += 1
        devided_two_price[x] -= 1
    elif devided_two_price[x] >= devided_two_price[x+1]:
        use_ticket_list[x] += 1
        devided_two_price[x] -= 1
    else:
        x += 1
        use_ticket_list[x] += 1
        devided_two_price[x] -= 1
    if x == n:
        x = 0
        a -= 1

for i in range(n):
    sum += item_price[i] // (2**use_ticket_list[i])

print(sum)

Submission status: Runtime Error

Solution code:
N,M = (int(i) for i in input().split())
A = [int(i) for i in input().split()]

A = sorted(A,reverse=True)
#print(A)
X = M
for i in range(M):
    A[0] //= 2
    X -= 1
    count = 0
    for j in range(M):
        if A[j] < A[j+1]:
            x = A[j]
            A[j] = A[j+1]
            A[j+1] = x
            count += 1
        else:
            break
            
    if count >= X:
        for j in range(X):
            A[j] //= 2
        break
    else:
        for j in range(count):
            A[j] //= 2
            X -= count
        A = sorted(A,reverse=True)
        
        
ans = 0
for i in A:
    ans += i

print(ans)

Submission status: Runtime Error

Solution code:
n, m = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
from collections import deque
import bisect
d = deque(A)
index = bisect.bisect_left(d, 2)
for _ in range(m):
    max_ = d.pop()
    tmp = max_ // 2
    index = bisect.bisect_left(d, tmp)
    d.insert(index, tmp)
print(sum(d))

Submission status: Runtime Error

Solution code:
import bisect
import sys

inf = sys.maxsize
N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort()

for i in range(M):
    x = A.pop(N-1)
    if x == 0:
        break
    x = x // 2
    A.insert(bisect.bisect_left(A, x), x)
print(sum(A)

Submission status: Runtime Error

Solution code:
N, M = (int(i) for i in input().split())
A = [int(i) for i in input().split()] 
for i in range(M):
    A = sorted(A, reverse=True)
    A[0]=A[0]//2
    print(A)
print(sum(A))

Submission status: Runtime Error

Solution code:
import bisect
n,m=map(int,input().split())
A=sorted(list(map(int,input().split())))
c=A.pop()//2
l=[c]
for _ in range(m-1):
  c=l.pop()
  if c>=A[-1]:
    c//=2
    bisect.insort_left(l,c)
  else:
    l+=[c]
    c=A.pop()//2
    bisect.insort_left(l,c)
print(sum(A)+sum(l))

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
A = list(map(int, input().split()))

A.sort()
tmp = A.pop(-1)
index = 0
for _ in range(M):
  tmp //= 2
  if tmp < A[-1]:
    A.append(tmp)
    tmp = A.pop(-2)
    A.sort()
A.append(tmp)

print(sum(A))

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
A = list(map(int,input().split()))
def waribiki():
    global M
    A[-1]=A[-1]//2
    M-=1
    if A[-2]<A[-1]:
        waribiki()
while M>0:
    A.sort()
    waribiki()
print(sum(A))

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
A = list(map(int, input().split()))

A = sorted(A)[::-1]

waribiki = 0
index = 0

if len(A)==1:
    print(A[0]//pow(2,M))
    exit()

while waribiki < M:
    if index < N and A[index]>2 and A[index+1]>2:
        x = A[index] // A[index+1]
        if x+waribiki>M: x = M-waribiki
    else: x = 1

    if A[index] > 2:
        A[index] = A[index]//pow(2, x)
        waribiki+=x

    index += 1
    if index==N: index=0

print(sum(A))

Submission status: Runtime Error

Solution code:
num ,m =map(int,input().split())
arr = sorted(list(map(int,input().split())),reverse=True)

for i in range(m):
    for j in range(len(arr)):
        if arr[j]//2 < arr[j+1]:
            arr[j] = arr[j] //2
            arr.sort(reverse=True)
            break
print(sum(arr))

Submission status: Runtime Error

Solution code:

n,m = map(int, input().split())
a = list(map(int, input().split()))

a = sorted(a)
b = []

tmp = a[-1]
b.append(tmp/2)
a.pop()


for i in range(m-1):
  tmp = a[-1]
  b_max = max(b)
  if tmp>b_max:
    b.append(tmp/2)
    a.pop()
  else:
    b = sorted(b)
    b[-1] /= 2

a = [int(ai) for ai in a]
b = [int(bi) for bi in b]

print(sum(a+b))

Submission status: Runtime Error

Solution code:
num ,m =map(int,input().split())
arr = sorted(list(map(int,input().split())),reverse=True)
print(arr)

for i in range(m):
    for j in range(len(arr)):
        if arr[j]//2 < arr[j+1]:
            arr[j] = arr[j] //2
            arr.sort(reverse=True)
            break

    print(arr)

print(sum(arr))

Submission status: Runtime Error

Solution code:
N,M=map(int,input().split())
A=list(map(int,input().split()))
A.sort(reverse=True)
while M>0:
    if A[0]//2<A[1]:
        A_0=A[0]
        i=0
        while A[i]>=A_0 and i<M and i<N:
            A[i]=A[i]//2
            i+=1
        A.sort(reverse=True)
        M-=i
    else:
        A[0]=A[0]//2
        M-=1
print(sum(A))

Submission status: Runtime Error

Solution code:
import math

n, m = map(int, input().split())
item_price = list(map(int, input().split()))
# n, m = (4, 4)
# item_price = [1, 9, 3, 5]
item_price.sort(reverse=True)
devided_two_price = [math.ceil(math.log2(i)) for i in item_price]
use_ticket_list = [0] * n
sum = 0

x = 0
for i in range(m):
    if devided_two_price[x] == 2:
        x += 1
        use_ticket_list[x] += 1
        devided_two_price[x] -= 1
    elif devided_two_price[x] >= devided_two_price[x+1]:
        use_ticket_list[x] += 1
        devided_two_price[x] -= 1
    else:
        x += 1
        use_ticket_list[x] += 1
        devided_two_price[x] -= 1

for i in range(n):
    sum += item_price[i] // (2**use_ticket_list[i])

print(sum)

Submission status: Runtime Error

Solution code:
n,m = map(int, input().split())

a_list = list(map(int,input().split()))

count = 0

while m>count:
    a_list.sort(reverse=True)
    a_list[0] = a_list[0] // 2
    count += 1
    if a_list[0] >= a_list[1]:
        a_list[0] = a_list[0] // 2
        count += 1
        
print(sum(a_list))

Submission status: Runtime Error

Solution code:
import sys
import bisect
input=sys.stdin.readline

n,m=map(int, input().split())
a=list(map(int, input().split()))

a.sort()

e=a[:n-m-1]
d=a[n-m-1:]
f=0

for _ in range(m):
    val=d.pop()//2
    if val > d[0]:
        bisect.insort(d, val)
    else:
        f+=val

print(sum(e)+sum(d)+f)

Submission status: Runtime Error

Solution code:
import bisect

n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
a.sort()
b = [0]
for _ in range(m):
    if a[-1] > b[-1]:
        am = a.pop()
        am = am // 2
        bisect.insort_left(b, am)
    else:
        bm = b.pop()
        bm = bm // 2
        bisect.insort_left(b, bm)
        
    
print(sum(a)+sum(b))

Submission status: Runtime Error

Solution code:
import math

n, m = map(int, input().split())
item_price = list(map(int, input().split()))
# n, m = (4, 4)
# item_price = [1, 9, 3, 5]
item_price.sort(reverse=True)
devided_two_price = [math.ceil(math.log2(i)) for i in item_price]
use_ticket_list = [0] * n
print(devided_two_price)
sum = 0

x = 0
for i in range(m):
    if devided_two_price[x] == 2:
        x += 1
        use_ticket_list[x] += 1
        devided_two_price[x] -= 1
    elif devided_two_price[x] >= devided_two_price[x+1]:
        use_ticket_list[x] += 1
        devided_two_price[x] -= 1
    else:
        x += 1
        use_ticket_list[x] += 1
        devided_two_price[x] -= 1

print(devided_two_price)
print(use_ticket_list)

for i in range(n):
    sum += item_price[i] // (2**use_ticket_list[i])

print(sum)

Submission status: Runtime Error

Solution code:
a = list(map(int, input().split(' ')))
a.sort()
if n > 1:
    for i in range(m):
        while a[-1] >= a[-2] and m > 0:
            a[-1] = a[-1] // 2
            m -= 1
        a.sort()
else:
    a[0] = a[0] // (2**m) 
print(sum(a))

Submission status: Runtime Error

Solution code:
N,M=map(int, input().split())
A=list(map(int, input().split()))
A.index(max(A))
A.sort()
a=A.pop()
b=A.pop()
for i in range(M):
    if a>=b:
        a=a//2
    else:
        A.append(a)
        A.append(b//2)
        A.sort()
        a=A.pop()
        b=A.pop()
        
print(sum(A)+a+b)

Submission status: Runtime Error

Solution code:
import math

n, m = map(int, input().split())
a = list(map(int, input().split()))
a.append(0)
a.sort(reverse=True)


def waru(i, tempb):
    a[i - 1] = a[i]
    a[i] = tempb

    if a[i] < a[i + 1]:
        waru(i + 1, tempb)


while m > 0:
    a[0] /= 2
    if a[0] < a[1]:
        waru(1, a[0])
    m -= 1

b = []
for i in a:
    b.append(math.floor(i))

print(sum(b))

Submission status: Runtime Error

Solution code:
from bisect import insort_left
from collections import deque
N, M = map(int, input().split())
A = list(map(int, input().split()))

A.sort()
A = deque(A)

for _ in range(M):
    a = A.pop()
    insort_left(A, a//2)
    
print(sum(A))

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
A = [int(a) for a in input().split()]
q = []
for a in A:
    heapq.heappush(q, -a)
    
for _ in range(M):
    tmp = -heapq.heappop(q)
    heapq.heappush(q, -(tmp//2))
print(-sum(q))

Submission status: Runtime Error

Solution code:
n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort(reverse=True)
for j in range(m):
  if a[0] >= a[1]:
    a[0] //= 2
  else:
    a[1] //= 2
  if max(a[0], a[1]) < a[2]:
    a.sort(reverse=True)
print(sum(a))

Submission status: Runtime Error

Solution code:
def main():
    n, m = map(int, input().split())
    a = list(map(int, input().split()))

    a = sorted(a)

    ans = 0

    for i in range(m):
        a[n-1] = a[n-1]//2
        func(n-1, a)

    ans = sum(a)
    print(ans)

def func(i:int, ls:list):
    if i == 0:
        return
    else:
        if ls[i] < ls[i-1]:
            ls[i], ls[i-1] = ls[i-1], ls[i]
            i -= 1
            func(i, ls)

if __name__=="__main__":
    main()

Submission status: Runtime Error

Solution code:
import sys

def input():
    return sys.stdin.readline()

N,M = map(int,input().split())


A = list(map(int,input().split()))

A.sort(reverse=True)

while(M>0):
    A[0] = A[0]//2 
    M = M-1
    if(A[0] < A[1]):
        A.sort(reverse=True)

print(sum(A))

Submission status: Runtime Error

Solution code:
import bisect
from collections import deque
N, M = map(int, input().split())
B = [int(x) for x in input().split()]
B = sorted(B)
A = deque()
for i in range(N):
    A.append(B[i])
#print(A)
for i in range(M):
    value = A.pop()
    value = value//2
    bisect.insort_left(A, value)
#print(A)
ans = sum(A)
print(ans)

Submission status: Runtime Error

Solution code:
N, K, Q = map(int,input().split())

A = [int(input()) for _ in range(Q) ]

L = [0 for _ in range(N) ]

for i in range(Q):
    L[A[i]-1] = L[A[i]-1]+1

for i in range(N):
    L[i] = K - Q + L[i]
    if(L[i]>0):
        print('Yes')
    else:
        print('No')

Submission status: Runtime Error

Solution code:
s = input().split()
# N = int(s[0])
# M = int(s[1])
A = list(map(int, input().split()))

for i in range(s[1]):
    j = A.index(max(A))
    A[j] //= 2

print(sum(A))

Submission status: Runtime Error

Solution code:
import bisect
from collections import deque

n, m = map(int, input().split())
a = list(map(int, input().split()))

a.sort()

a = deque(a)

for i in range(m):
    saidai = a.pop()
    sounyu = saidai // 2
    bisect.insort(a, sounyu)

print(sum(a))

Submission status: Runtime Error

Solution code:
import math
import bisect
from collections import deque
n, ticket = map(int, input().split())
L = list(map(int, input().split()))


if len(L) == 1:
    print(math.floor(L[0] / (2**ticket)))
else:
    L.sort()
    L = deque(L)
    for _ in range(ticket):
        top = L.pop()
        top /= 2
        bisect.insort_left(L,top)
    print(sum(map(math.floor, L)))

Submission status: Runtime Error

Solution code:
n,m=map(int,input().split())
a=list(map(int,input().split()))
x=0
for i in range(m+1):
  a.sort(reverse=1)
  print(a)
  x=a[0]//2
  a[0]=x
print(sum(a))

Submission status: Runtime Error

Solution code:
n,m=map(int, input().split())
a=list(map(int, input().split()), reverse=True)

while(m>0):
    max_index=a.index(max(a))
    a[max_index] = a[max_index]//2
    m-=1
print(sum(a))

Submission status: Runtime Error

Solution code:
N,M = map(int,input().split())
h=[]
li = input().split()
for i in li:
    heapq.heappush(h, -int(i))

for i in range(M):
    z = heapq.heappop(h) / 2
    heapq.heappush(h, z)
c=0
for i in h:
    c += int(i)
print(-c)

Submission status: Runtime Error

Solution code:
import bisect
from collections import deque

N, M = map(int, input().split())
A = list(map(int, input().split()))
A = deque(sorted(A, reverse=True))
#A.sort(reverse=True)

for i in range(M):
    a = A.popleft()
    a /= 2
    index = bisect.bisect_left(A, a)
    A.insert(index-1, a)

ans = 0
for a in A:
    ans += a//1
print(int(ans))

Submission status: Runtime Error

Solution code:
import sys
import bisect
input=sys.stdin.readline

n,m=map(int, input().split())
a=list(map(int, input().split()))

a.sort()

e=a[:n-m]
d=a[n-m:]
f=[0]

for _ in range(m):
    val=d.pop()//2
    if val > d[0]:
        bisect.insort(d, val)
    else:
        f.append(val)

print(sum(e)+sum(d)+sum(f))

Submission status: Runtime Error

Solution code:
n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort(reverse=True)
for j in range(m):
  if a[0] >= a[1]:
    a[0] //= 2
  else:
    a[1] //= 2
    a.sort(reverse=True)
print(sum(a))

Submission status: Runtime Error

Solution code:
import sys
import bisect
input=sys.stdin.readline

n,m=map(int, input().split())
a=list(map(int, input().split()))

a.sort()

e=a[:n-m]
d=a[n-m:]

for _ in range(m):
    val=d.pop()//2
    if val > d[0]:
        bisect.insort(d, val)
    else:
        e.append(val)

print(sum(e)+sum(d))

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!
data=input().rstrip().split(" ")
data[0]=int(data[0])
data[1]=int(data[1])
yen=input().rstrip().split(" ")
for i in range(data[0]):
    yen[i]=int(yen[i])
    
for i in range(data[1]):
    if(yen[0] < yen[1]):
        yen=sorted(yen,reverse=True)
    yen[0]=int(yen[0]/2)

ans=0
for i in range(data[0]):
    ans= ans + yen[i]
print(ans)

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
Alist = list(map(int, input().split()))

def solve(A, M):
    if len(A) > 1:
        if M==1:
            B = sum(A[1:]) + A[0]//2
        else:
            A = [A[0]//2] + A[1:]
            A.sort(reverse=True)
            B = solve(A, M-1)
    else:
        B = A[0] // (2**M)
    return B

Alist.sort(reverse=True)
B = solve(Alist, M)
print(B)

Submission status: Runtime Error

Solution code:
n,m = map(int, input().split())
a = list(map(int, input().split()))
a.sort(reverse=True)
for i in range(m):
    a[0] = a[0]//2
    if a[0]<a[1]:
        a.sort(reverse=True)
print(sum(a))

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
A = sorted([int(x) for x in input().split()])

for i in range(M):
    A[-1] = A[-1]//2
    if A[-1] < A[-2]:
        A.sort()
print(sum(A))

Submission status: Runtime Error

Solution code:
import bisect
from collections import deque
import math

N, M = map(int, input().split())
_A = list(map(int, input().split()))
A = deque(sorted(_A, reverse=True))
#A  = sorted(_A, reverse=True)

for i in range(M):
    a = A.popleft()
    a /= 2
    index = bisect.bisect_left(A, a)
    A.insert(index-1, a)

ans = 0
for a in A:
    ans += math.floor(a)
print(int(ans))

Submission status: Runtime Error

Solution code:
import math
N, M = map(int,input().split())

A = [int(x) for x in input().split()]
A.sort()

for i in range(M+1):
    first = A[0]
    second = A[1]
    while(i<M):
        first = first//2
        i += 1
        if(first < second):
            break
    A[0] = first
    A.sort()

print(sum(A))

Submission status: Runtime Error

Solution code:
from bisect import bisect
n,m,*a=map(int,open(0).read().split())
a.sort()
def calc(a,m):
    if m==0:
        return sum(a)
    else:
        tmp = a.pop()>>1
        if tmp >0:
            tmp_index = bisect(a,tmp)
            a.insert(tmp_index,tmp)
        elif a==[]:
            return 0
        return calc(a,m-1)
print(calc(a,m))

Submission status: Runtime Error

Solution code:
temp = list(map(int, input().split()))
N = temp[0] #品物の数
M = temp[1] #割引券の枚数
A = list(map(int, input().split())) #品物の値段のリスト

print(N)
print(M)
print(A)

A.sort(reverse=True)

while(M>0):
  A[0] = A[0]//2
  M -= 1
  A.sort(reverse=True)
  print(A)

total = 0
for i in range(N):
  total += A[i]
print(total)

Submission status: Runtime Error

Solution code:
from collections import deque
import bisect
N, M = map(int, input().split())
A = sorted(list(map(int, input().split())))
A = deque(A)
for i in range(M):
    A[N-1] //= 2
    if N >=2 and A[N-1] > A[N-2]:
        continue
    p = A.pop()
    index = bisect.bisect_left(A, p)
    A.insert(index, p)
print(sum(A))

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!
n,m=map(int,input().split())
l=list(map(int,input().split()))
l.sort(reverse=True)
for i in range(m):
    l[0]=l[0]//2
    if l[0]<l[1]:
        l.sort(reverse=True)
print(sum(l))

Submission status: Runtime Error

Solution code:
import math

N, M = [int(x) for x in input().split()]
A_list = [int(x) for x in input().split()]

A_list.sort()
while M > 0:
    A_list[-1] = math.floor(A_list[-1] / 2)
    if A_list[-1] < A_list[-2]:
        A_list.sort()
    M -= 1

print(sum(A_list))

Submission status: Runtime Error

Solution code:
def solve(N, M, A):
    from math import log, ceil
    from heapq import heappush, heappop, heapify
    Q = [-a for a in A]
    heapify(Q)

    if len(A) == 1:
        return A[0]>>M

    while Q and M:
        a = - heappop(Q)
        b = - Q[0]
        if b < a:
            k = min(M, ceil(log(a,2) - log(b, 2)))
        else:
            k = min(M, 1)
        c = a >> k
        #print("prev=%d, dis=%d, %d - %d = %d" % (a, c, M, k, M-k))
        M -= k
        heappush(Q, -c)
    return sum(-a for a in Q)


def main():
    import sys
    input = sys.stdin.readline

    N, M = map(int, input().split())
    A = sorted([int(x) for x in input().split()], reverse=True)

    print(solve(N, M, A))

def gen():
    import random
    with open("9", "w") as f:
        print(10**5, 10**5, file=f)
        print(*[random.randint(1, 10**9) for i in range(10**5)],file=f)

main()

Submission status: Runtime Error

Solution code:
import sys
def input():
	return sys.stdin.readline().strip()

N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
for i in range(N):
	A[i] = -A[i]

heapq.heapify(A)


for i in range(M):
	x = heapq.heappop(A)
	x /= 2
	x = heapq.heappush(A, x)

total = 0
for i in range(N):
	total -= math.ceil(A[i])

print(total)

Submission status: Runtime Error

Solution code:
    print(result)

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(100002)
input=sys.stdin.readline
n,m=map(int,input().split())
a=list(map(int,input().split()))
r=[0]
a.sort(reverse=True)
for i in range(m):
    d=a.pop(0)
    if r[-1]>=d:
        r[-1]//=2
        r.append(d)
        r.sort()
    else:
        d//=2
        r.append(d)
        r.sort()
print(sum(a)+sum(r))

Submission status: Runtime Error

Solution code:
import heapq

N , M = map(int,input().split())
A = list(map(lambda x:-int(x),input().split()))

heapq.heapify(A)
for _ in range(M):
    largest = heapq.heappop(A)
    largest = -((-largest)//2)
    if largest != 0:
        heapq.heappush(A, largest)

print(-sum(A))

Submission status: Runtime Error

Solution code:
import sys, math
mod = 1000000007
def get_array(): return list(map(int, sys.stdin.readline().split()))
def get_ints(): return map(int, sys.stdin.readline().split())
def input(): return sys.stdin.readline()
def print_array(a): print(" ".join(map(str, a)))
def main():
        n, m = get_ints()
        a = get_array()
        a.sort()
        while m > 0:
                x = int(math.log2(a[n - 1] / a[n - 2])) + 1
                x = min(x, m)
                a[n - 1] //= (2 ** x)
                m -= x
                a.sort()
        print(sum(a))
if __name__ == "__main__":
        main()

Submission status: Runtime Error

Solution code:
N,M = [int(i) for i in input().split()]
data = [int(i) for i in input().split()]


for i in range(M):
    data[data.index(max(data))] /= 2

for i in range(M):
    data[i] = data[i]//1


print(int(sum(data)))

Submission status: Runtime Error

Solution code:
n,m=map(int,input().split())
A=[int(i) for i in input().split()]

A.sort()
#print(A)
for i in range(m):
    A[-1]=A[-1]//2
    if A[-1]<A[-2]:
        A.sort()
    #print(A)
print(sum(A))