Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
L=list(map(int,input().split()))
L.sort()
from collections import deque
Ld=deque(L)
A=[0]
Ad=deque(A)
for i in range(m):
    if Ld==deque([]):
        if Ad==deque([]):
            break
        else:
            if Ad[-1]!=0:
                x=Ad.pop()//2
                if x>=Ad[-1]:
                    Ad.append(x)
                else:
                    Ad.insert(0,x)
            else:
                break
    else:
        if Ld[-1] >=Ad[-1]:
            x=Ld.pop()//2
            if x>=Ad[-1]:
                Ad.append(x)
            else:
                Ad.insert(0,x)
        else:
            x=Ad.pop()//2
            if x>=Ad[-1]:
                Ad.append(x)
            else:
                Ad.insert(0,x)
print(sum(list(Ld))+sum(list(Ad)))

Fixed submission:
n,m=map(int,input().split())
L=list(map(int,input().split()))
Lh=list(map(lambda x: x*(-1), L))
import heapq
#heapqは置き直さなくてOK
heapq.heapify(Lh)
for _ in range(m):
    x=heapq.heappop(Lh)
    heapq.heappush(Lh,(x+1)//2)#負の数の割り算のため+1
print(sum(Lh)*(-1))

Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
L=list(map(int,input().split()))
L.sort()
from collections import deque
Ld=deque(L)
A=[0]
Ad=deque(A)
for i in range(m):
    if Ld==deque([]):
        if Ad==deque([]):
            break
        else:
            if Ad[-1]!=0:
                x=Ad.pop()//2
                if x>=Ad[-1]:
                    Ad.append(x)
                else:
                    Ad.insert(0,x)
            else:
                break
    else:
        if Ld[-1] >=Ad[-1]:
            x=Ld.pop()//2
            if x>=Ad[-1]:
                Ad.append(x)
            else:
                Ad.insert(0,x)
        else:
            x=Ad.pop()//2
            if x>=Ad[-1]:
                Ad.append(x)
            else:
                Ad.insert(0,x)
print(sum(list(Ld))+sum(list(Ad)))

Fixed submission:
n,m=map(int,input().split())
L=list(map(int,input().split()))
Lh=list(map(lambda x: x*(-1), L))
import heapq
#heapqは置き直さなくてOK
heapq.heapify(Lh)
for _ in range(m):
    x=heapq.heappop(Lh)
    heapq.heappush(Lh,(x+1)//2)#負の数の割り算のため+1
print(sum(Lh)*(-1))

Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
L=list(map(int,input().split()))
L.sort()
from collections import deque
Ld=deque(L)
A=[0]
Ad=deque(A)
for i in range(m):
    if L[-1] >=A[-1]:
        x=L.pop()//2
        if x>=A[-1]:
            A.append(x)
        else:
            A.insert(0,x)
    else:
        x=A.pop()//2
        if x>=A[-1]:
            A.append(x)
        else:
            A.insert(0,x)
print(sum(L)+sum(A))

Fixed submission:
n,m=map(int,input().split())
L=list(map(int,input().split()))
Lh=list(map(lambda x: x*(-1), L))
import heapq
#heapqは置き直さなくてOK
heapq.heapify(Lh)
for _ in range(m):
    x=heapq.heappop(Lh)
    heapq.heappush(Lh,(x+1)//2)#負の数の割り算のため+1
print(sum(Lh)*(-1))

Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
L=list(map(int,input().split()))
import bisect
from collections import deque
L.sort()
Ld=deque(L)
for i in range(m):
    x=L.pop()//2
    y=bisect.bisect_left(L,x)
    L.insert(y,x)
print(sum(L))

Fixed submission:
n,m=map(int,input().split())
L=list(map(int,input().split()))
Lh=list(map(lambda x: x*(-1), L))
import heapq
#heapqは置き直さなくてOK
heapq.heapify(Lh)
for _ in range(m):
    x=heapq.heappop(Lh)
    heapq.heappush(Lh,(x+1)//2)#負の数の割り算のため+1
print(sum(Lh)*(-1))

Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
L=list(map(int,input().split()))
import bisect
L=list(sorted(L))
for i in range(m):
    x=L.pop()//2
    y=bisect.bisect_left(L,x)
    L.insert(y,x)
print(sum(L))

Fixed submission:
n,m=map(int,input().split())
L=list(map(int,input().split()))
Lh=list(map(lambda x: x*(-1), L))
import heapq
#heapqは置き直さなくてOK
heapq.heapify(Lh)
for _ in range(m):
    x=heapq.heappop(Lh)
    heapq.heappush(Lh,(x+1)//2)#負の数の割り算のため+1
print(sum(Lh)*(-1))