Buggy python submission (verdict: Runtime Error):
import math
import sys

N, M = map(int,input().split())
A = list(map(int,input().split()))
if N == 1:
    while A[0] > 0:
        A[0] = A[0]//2
    print(0)
    sys.exit()

list.sort(A,reverse = True)
a = A[0]
b = A[1]
x = 0
for _ in range(M):
    a = A[0]
    b = A[1]
    x = max(math.ceil(math.log2(a/b)),1)
    if M >= x:
        if x <= 3:
            a = a//(2**x)
            _ += x
        else:
            a = 0
            _ += x
    else:
        if M <= 3:
            a = a//(2**M)
            _ = M
        else:
            a = 0
            _ = M
    A[0] = a
    for i in range(0,N-1):
        if A[i] < A[i+1]:
            A[i] , A[i+1] = A[i+1] , A[i]

print(sum(A))

Fixed submission:
import sys
import os
import math
import heapq

N, M = map(int,input().split())
A = list(map(int,input().split()))
#大きいものから取り出したいので-1倍してqueueに入れる

Q = []
for a in A:
    heapq.heappush(Q,-a)

for i in range(M):
    first = -heapq.heappop(Q)
    first = first//2
    heapq.heappush(Q,-first)

print(-sum(Q))

Buggy python submission (verdict: Runtime Error):
import math
import sys

N, M = map(int,input().split())
A = list(map(int,input().split()))
if N == 1:
    while A[0] > 0:
        A[0] = A[0]//2
    print(0)
    sys.exit()

list.sort(A,reverse = True)
a = A[0]
b = A[1]
x = 0
for _ in range(M):
    a = A[0]
    b = A[1]
    x = max(math.ceil(math.log2(a/b)),1)
    if M >= x:
        a = a//(2**x)
        _ += x
    else:
        a = a//(2**M)
        _ = M
    A[0] = a
    for i in range(0,N-1):
        if A[i] < A[i+1]:
            A[i] , A[i+1] = A[i+1] , A[i]

print(sum(A))

Fixed submission:
import sys
import os
import math
import heapq

N, M = map(int,input().split())
A = list(map(int,input().split()))
#大きいものから取り出したいので-1倍してqueueに入れる

Q = []
for a in A:
    heapq.heappush(Q,-a)

for i in range(M):
    first = -heapq.heappop(Q)
    first = first//2
    heapq.heappush(Q,-first)

print(-sum(Q))

Buggy python submission (verdict: Runtime Error):
import sys

N, M = map(int,input().split())
A = list(map(int,input().split()))
if N == 1:
    while A[0] > 0:
        A[0] = A[0]//2
    print(0)
    sys.exit()

list.sort(A,reverse = True)
for i in range(M):
    while A[0] >= A[1]:
        A[0] = A[0]//2
    for i in range(0,M-1):
        if A[i] < A[i+1]:
            A[i] , A[i+1] = A[i+1] , A[i]

print(sum(A))

Fixed submission:
import sys
import os
import math
import heapq

N, M = map(int,input().split())
A = list(map(int,input().split()))
#大きいものから取り出したいので-1倍してqueueに入れる

Q = []
for a in A:
    heapq.heappush(Q,-a)

for i in range(M):
    first = -heapq.heappop(Q)
    first = first//2
    heapq.heappush(Q,-first)

print(-sum(Q))

Buggy python submission (verdict: Runtime Error):
N, M = map(int,input().split())
A = list(map(int,input().split()))
if N == 1:
    while A[0] > 0:
        A[0] = A[0]//2
    print(0)
    sys.exit()

list.sort(A,reverse = True)
for i in range(M):
    while A[0] >= A[1]:
        A[0] = A[0]//2
    for i in range(0,M-1):
        if A[i] < A[i+1]:
            A[i] , A[i+1] = A[i+1] , A[i]

print(sum(A))

Fixed submission:
import sys
import os
import math
import heapq

N, M = map(int,input().split())
A = list(map(int,input().split()))
#大きいものから取り出したいので-1倍してqueueに入れる

Q = []
for a in A:
    heapq.heappush(Q,-a)

for i in range(M):
    first = -heapq.heappop(Q)
    first = first//2
    heapq.heappush(Q,-first)

print(-sum(Q))

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int,input().split())
A = list(map(int,input().split()))

maxi = 0
idx = 0
for i in range(M):
    maxi = max(A)
    idx = A.index(maxi)
    A[idx] = maxi//2
print(sum(A))

Fixed submission:
import sys
import os
import math
import heapq

N, M = map(int,input().split())
A = list(map(int,input().split()))
#大きいものから取り出したいので-1倍してqueueに入れる

Q = []
for a in A:
    heapq.heappush(Q,-a)

for i in range(M):
    first = -heapq.heappop(Q)
    first = first//2
    heapq.heappush(Q,-first)

print(-sum(Q))