Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
lista = [int(i) for i in input().split()]
lista.sort()

dic = {}
for i in range(31):
    dic[i] = []

i2 = 0

for i in range(len(lista)):
    while(lista[i]>=2**(i2+1)):
        i2+=1
    dic[i2].append(lista[i])
    
#print(dic)

end = False
for t in range(i2,0,-1):
    list_d = dic[t]
    list_d.sort()
    loop = len(list_d)
    if loop<m:
        for i in range(loop):
            list_d[i] = list_d[i]/2
        dic[t-1] = dic[t-1]+list_d
        list_d = []
        m = m-loop
    else:
        for i in range(loop):
            tmp = list_d[-1]
            dic[t-1].append(tmp/2)
            list_d =  list_d[:-1]
            m = m-1
            if m==0:
                end = True
                dic[t] = list_d
                break

    dic[t] = list_d
    if end == True:
        break
        
        
"""print(dic)
print(m)"""
ans = 0
if m > 0:
    ans = n-m
    if ans >= 0:
        print(n-m)
    else:
        print(0)
else:
    for i in range(t+1):
        list_d = dic[i]
        #print(i,list_d)
        for l in range(len(list_d)):
            tmp = list_d[l]
            ans+=int(tmp)
    print(ans)

Fixed submission:
import heapq
n, m = map(int, input().split())
a = list(map(int, input().split()))
a = list(map(lambda x: x * (-1), a))
heapq.heapify(a)
while m != 0:
    price = heapq.heappop(a)
    price = price/2
    m -= 1
    heapq.heappush(a, price)

for i in range(len(a)):
    a[i] = int(a[i])
print(sum(a) * (-1))

Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
lista = [int(i) for i in input().split()]
lista.sort()

dic = {}
for i in range(31):
    dic[i] = []

i2 = 0

for i in range(len(lista)):
    while(lista[i]>=2**(i2+1)):
        i2+=1
    dic[i2].append(lista[i])
    
#print(dic)

end = False
for t in range(i2,0,-1):
    list_d = dic[t]
    list_d.sort()
    loop = len(list_d)
    for i in range(loop):
        tmp = list_d[-1]
        dic[t-1].append(tmp/2)
        list_d =  list_d[:-1]
        m = m-1
        if m==0:
            end = True
            dic[t] = list_d
            break
    
    dic[t] = list_d
    if end == True:
        break
        
        
"""print(dic)
print(m)"""
ans = 0
if m > 0:
    ans = n-m
    if ans >= 0:
        print(n-m)
    else:
        print(0)
else:
    for i in range(t+1):
        list_d = dic[i]
        #print(i,list_d)
        for l in range(len(list_d)):
            tmp = list_d[l]
            ans+=int(tmp)
    print(ans)

Fixed submission:
import heapq
n, m = map(int, input().split())
a = list(map(int, input().split()))
a = list(map(lambda x: x * (-1), a))
heapq.heapify(a)
while m != 0:
    price = heapq.heappop(a)
    price = price/2
    m -= 1
    heapq.heappush(a, price)

for i in range(len(a)):
    a[i] = int(a[i])
print(sum(a) * (-1))

Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
lista = [int(i) for i in input().split()]
lista.sort()

dic = {}
for i in range(31):
    dic[i] = []

i2 = 0

for i in range(len(lista)):
    while(lista[i]>=2**(i2+1)):
        i2+=1
    dic[i2].append(lista[i])
    
#print(dic)

end = False
for t in range(i2,0,-1):
    list_d = dic[t]
    list_d.sort()
    loop = len(list_d)
    for i in range(loop):
        tmp = list_d[-1]
        dic[t-1].append(tmp/2)
        list_d =  list_d[:-1]
        m = m-1
        if m==0:
            end = True
            dic[t] = list_d
            break
    
    dic[t] = list_d
    if end == True:
        break
        
        
"""print(dic)
print(m)"""
ans = 0
if m > 0:
    ans = n-m
    if ans >= 0:
        print(n-m)
    else:
        print(0)
else:
    for i in range(t+1):
        list_d = dic[i]
        #print(i,list_d)
        for l in range(len(list_d)):
            tmp = list_d[l]
            ans+=int(tmp)
    print(ans)

Fixed submission:
import heapq
n, m = map(int, input().split())
a = list(map(int, input().split()))
a = list(map(lambda x: x * (-1), a))
heapq.heapify(a)
while m != 0:
    price = heapq.heappop(a)
    price = price/2
    m -= 1
    heapq.heappush(a, price)

for i in range(len(a)):
    a[i] = int(a[i])
print(sum(a) * (-1))