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: Accepted

Solution code:
# coding: utf-8
import heapq


def solve(*args: str) -> str:
    n, m = map(int, args[0].split())
    A = list(map(lambda _: -int(_), args[1].split()))
    heapq.heapify(A)

    for _ in range(m):
        a = heapq.heappop(A)
        heapq.heappush(A, int(a/2))

    return str(-sum(A))


if __name__ == "__main__":
    print(solve(*[input() for _ in range(2)]))

Submission status: Accepted

Solution code:
#17:30
n,m = map(int,input().split())
import heapq
h = list(map(lambda x:-int(x),input().split()))
heapq.heapify(h)
for _ in range(m):
  now = heapq.heappop(h)
  heapq.heappush(h,-((-now)//2))
print(-sum(h))

Submission status: Accepted

Solution code:
from heapq import heappush, heappop, heapify

n, m = list(map(int, input().split()))
q = list(map(lambda x: -int(x), input().split()))
heapify(q)

for _ in range(m):
    highest = -heappop(q)
    heappush(q, -(highest // 2))

cost = -sum(q)

print(cost)

Submission status: Accepted

Solution code:
import heapq

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

heapq.heapify(A)

for i in range(M):
    big = (heapq.heappop(A) * -1) // 2
    heapq.heappush(A, big * -1)

print(-sum(A))

Submission status: Accepted

Solution code:
import heapq

N, M = map(int, input().split())
lst = [int(x) * -1 for x in input().split()]
heapq.heapify(lst)
for _ in range(M):
    n = heapq.heappop(lst)
    n = n * -1 // 2 * -1
    heapq.heappush(lst, n)
print(sum(lst) * -1)

Submission status: Accepted

Solution code:
import heapq
import math

n, m = map(int, input().split())
a = [int(x) for x in input().split()]
h = []

for i in a:
    heapq.heappush(h, -i)
#print(h)

for i in range(m):
    tmp = heapq.heappop(h)
    tmp = math.ceil(tmp/2)
    heapq.heappush(h, tmp)
#print(h)

print(-1*sum(h))

Submission status: Accepted

Solution code:
from heapq import heapify,heappop,heappush
n,m=map(int,input().split())#n:num m:ticket
a=[-int(_) for _ in input().split()]
heapify(a)
for i in range(m):
	num=heappop(a)*-1
	heappush(a,(num//2)*-1)
print(sum(a)*-1)

Submission status: Accepted

Solution code:
from heapq import heapify, heappop, heappush

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

heapify(A)
#print(A)
for i in range(M): 
    x = heappop(A)
    heappush(A, x/2)
    #print(i, A)
    
print(sum([-int(a) for a in A]))

Submission status: Accepted

Solution code:
#import sys
from heapq import heappush, heappop
#input = sys.stdin.readline
N,M = map(int, input().split())
A = []
for a in input().split():
  heappush(A,-int(a))

for _ in range(M):
  tmp = heappop(A)
  heappush(A, -(-tmp//2))

print(-sum(A))

Submission status: Accepted

Solution code:
import sys
from heapq import heappush, heappop
input = sys.stdin.readline
N,M = map(int, input().split())
A = []
for a in input().split():
  heappush(A,-int(a))

for _ in range(M):
  tmp = heappop(A)
  heappush(A, -(-tmp//2))

print(-sum(A))

Submission status: Accepted

Solution code:
from math import log2
from bisect import bisect_right
n, m = map(int, input().split())
a = [int(ai) for ai in input().split()]
a.sort()
b = [log2(ai) for ai in a]
ma = int(b[-1])
c = 0
tmp = 0
for t in range(-1, ma+1)[::-1]:
  i = bisect_right(b, t)
  d = n - i
  if c + d <= m:
    c += d
    for j in range(i, n):
      a[j] = a[j] / 2.0
  else:
    a.sort(reverse=True)
    for j in range(m-c):
      a[j] = a[j] / 2.0
    break
print(sum([int(ai) for ai in a]))

Submission status: Accepted

Solution code:
import heapq

# O(MlogN)
n,m = map(int,input().split())
a_list = list(map(lambda x: int(x)*(-1),input().split()))
heapq.heapify(a_list)

for _ in range(m):
    tmp_min = heapq.heappop(a_list)
    heapq.heappush(a_list, (-1)*(-tmp_min//2)) 

print(-sum(a_list))

Submission status: Accepted

Solution code:
import heapq

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

heapq.heapify(A_lis)

def discount(A_lis):
    popped = heapq.heappop(A_lis)
    heapq.heappush(A_lis,popped/2)
    return A_lis

for i in range(M):
    A_lis = discount(A_lis)
ans = 0
for i in A_lis:
    ans += int(i)
print(ans*(-1))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import heapq

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

a = [-int(a) for a in input().split()]
heapq.heapify(a)

for i in range(m):
    heapq.heappush(a, int(heapq.heappop(a) / 2))

print(sum(a) * -1)

Submission status: Accepted

Solution code:
import heapq
n, m = map(int, input().split())
lis = list(map(int,input().split()))
for i in range(n):
  lis[i] *= -1
lis.sort(reverse=True)
heapq.heapify(lis)
for m in range(m):
  a = -(-heapq.heappop(lis) // 2)
  heapq.heappush(lis, a)
print(-sum(lis))

Submission status: Accepted

Solution code:
def funcD():
    import heapq
    N, M = map(int, input().split())
    A = list(map(lambda x: -1 * int(x), input().split()))
    A.sort(reverse=True)
    heapq.heapify(A)
    for m in range(M):
        a = -(-heapq.heappop(A) // 2)
        heapq.heappush(A, a)
    print(-sum(A))


funcD()

Submission status: Accepted

Solution code:
import numpy as np
import heapq
n = list(map(int, input().split()))
h = list(map(lambda x: int(x)*-1, input().split()))
heapq.heapify(h)
for i in range(n[1]):
    small = heapq.heappop(h)
    heapq.heappush(h, -1*(-small//2))
print(-sum(h))

Submission status: Accepted

Solution code:
import heapq as hp
N, M = [int(item) for item in input().split()]
price_list = sorted([-1 * int(item) for item in input().split()])

total_m = 0

def discount(price_list, ticket_num):
    total_ticket =0
    hp.heapify(price_list)

    while total_ticket < ticket_num:
        temp = hp.heappop(price_list)
        hp.heappush(price_list, -1* (-1*temp//2))
        total_ticket += 1

    return price_list

res = discount(price_list, M)
print(-1 * sum(res))

Submission status: Accepted

Solution code:
import heapq

n, m = map(int, input().split())
a = list(map(lambda x : int(x) * (-1), input().split()))
heapq.heapify(a)

for i in range(m):
    maximum = heapq.heappop(a)
    heapq.heappush(a, (-1)*(-maximum//2))
print(-sum(a))

Submission status: Accepted

Solution code:
from heapq import heappush, heappop

n, m = map(int, input().split())
A = input().split()
hq = []
for a in A:
    heappush(hq, -1 * int(a))

for _ in range(m):
    tmp = -1 * heappop(hq)
    heappush(hq, -1 * (tmp // 2))

print(-sum(hq))

Submission status: Accepted

Solution code:
from heapq import heapify, heappush, heappop

n, m = map(int, input().split())
A = list(map(lambda x: int(x) * -1, input().split()))
heapify(A)

for _ in range(m):
    tmp = -1 * heappop(A)
    heappush(A, -1 * (tmp // 2))

print(-sum(A))

Submission status: Accepted

Solution code:
import heapq as hq
n,m = list(map(int,input().split()))
a = list(map(int,input().split()))
a_mi = [a[i]*(-1) for i in range(len(a))]
hq.heapify(a_mi)
for i in range(m):
    ai = hq.heappop(a_mi)
    hq.heappush(a_mi,((-1)*ai//2)*(-1))
ans = [hq.heappop(a_mi) for i in range(len(a_mi))]
print(sum(ans)*(-1))

Submission status: Accepted

Solution code:
import heapq
if __name__ == '__main__':
    N, M = map(int, input().split())
    A = list(map(lambda x: int(x) * (-1), input().split()))
    heapq.heapify(A)
    for _ in range(M):
        tmp = heapq.heappop(A)
        heapq.heappush(A, -(-tmp // 2))
    print(-sum(A))

Submission status: Accepted

Solution code:
import heapq

n, m = map(int, input().split())
a = [int(_) for _ in input().split()]

que = []
for i in range(n):
    heapq.heappush(que, -a[i])

for i in range(m):
    t = -heapq.heappop(que)
    t /= 2
    heapq.heappush(que,-t)

res = 0
for i in range(n):
    res += int(-que[i])

print(res)

Submission status: Accepted

Solution code:
from heapq import heappush, heappop
def main():
	(N, M) = map(int, input().split())
	hq =  list(map(lambda x:-x, map(int, input().split())))
	hq.sort()
	for i in range(M):
		b = - heappop(hq) // 2
		heappush(hq, -b)
	print(-sum(hq))
main()

Submission status: Accepted

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

a = list(map(lambda x: -int(x), input().split()))
heapq.heapify(a)

for i in range(m):
    heapq.heappush(a, int(heapq.heappop(a)/2))

print(-sum(a))

Submission status: Accepted

Solution code:
import heapq
n, m = map(int, input().split())
A = list(map(int, input().split()))
cost = []
heapq.heapify(cost)
for i in range(n):
    heapq.heappush(cost, -A[i])
for i in range(m):
    target = heapq.heappop(cost) / 2
    heapq.heappush(cost, target)
ans = [int(i) for i in cost]
print(-sum(ans))

Submission status: Accepted

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

import heapq
A_que = []
for i in A:
    A_que.append((-1) * i)
heapq.heapify(A_que)
for i in range(M):
    price = (-1) * heapq.heappop(A_que)
    price = price // 2
    heapq.heappush(A_que, (-1) * price)
print(-sum(A_que))

Submission status: Accepted

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

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

a = list(map(lambda x: x*(-1), A_list))

import heapq
import math


heapq.heapify(a)



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

res=0
for i in range(N):
        a[i] = -a[i]
        res += math.floor(a[i])

print(res)

Submission status: Accepted

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

a = list(map(lambda x: -int(x), input().split()))
heapq.heapify(a)

for i in range(M):
    heapq.heappush(a, int(heapq.heappop(a)/2))

print(-sum(a))

Submission status: Accepted

Solution code:
import heapq

N,M = map(int, input().split())
A = [int(i)*-1 for i in input().split()]
heapq.heapify(A)

for _ in range(M):
    heapq.heappush(A, int(heapq.heappop(A)/2))

print(sum(A)*-1)

Submission status: Accepted

Solution code:
import heapq

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


def solve():
    AA = [[-x, x] for x in A]

    heapq.heapify(AA)

    for i in range(M):
        x, y = heapq.heappop(AA)
        heapq.heappush(AA, [-(y//2), y//2])

    AAA = [x[1] for x in AA]
    return sum(AAA)


print(solve())

Submission status: Accepted

Solution code:
from collections import deque
N,M=map(int,input().split())
A=list(map(int,input().split()))
A.sort(reverse=True)
q1=deque(A)
q2=deque([])
for i in range(M):
  if len(q1)!=0 and (len(q2)==0 or q1[0]>=q2[0]):
    x=q1.popleft()
  else:
    x=q2.popleft()
  q2.append(x//2)
print(int(sum(q1)+sum(q2)))

Submission status: Accepted

Solution code:
def resolve():
    import heapq
    _,M = map(int,input().split())
    A = list(map(lambda x:(-1)*int(x),input().split()))
    heapq.heapify(A)
    for _ in range(M):
        heapq.heapreplace(A,(A[0]*(-1) // 2)*(-1))
    print((-1) * sum(A))    
resolve()

Submission status: Accepted

Solution code:
import heapq
N,M=map(int,input().split())
A=list(map(lambda x:int(x)*(-1),input().split()))
heapq.heapify(A)
    
for i in range(0,M):
    tmp=heapq.heappop(A)
    heapq.heappush(A,-int(-tmp/2))
print(-sum(A))

Submission status: Accepted

Solution code:
import heapq

n,m = map(int,input().split())
a_L = list(map(lambda x:int(x) * -1,input().split()))

heapq.heapify(a_L)
#a_L = list(sorted(a_L))
#max_num = a_L[0]
#a_L.append(max_num)

for val in range(0,m):
    a_min = heapq.heappop(a_L)
    a_min = (-1 * a_min)//2 * -1
    heapq.heappush(a_L,a_min)

print(-sum(a_L))

Submission status: Accepted

Solution code:
import heapq

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

heapq.heapify(A)

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

print(sum(A)*(-1))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import heapq

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

# Pythonのheapqは最小値しかとれないので、負の値に変換して扱う
a_list = list(map(lambda x: x * (-1), a_list))
heapq.heapify(a_list)

for _ in range(M):
    max_value = -heapq.heappop(a_list)
    heapq.heappush(a_list, -(max_value // 2))

ans = -sum(a_list)
print(ans)

Submission status: Accepted

Solution code:
import heapq
N, M = map(int, input().split())
A = list(map(int, input().split()))
AA = [[-x, x] for x in A]
heapq.heapify(AA)
for i in range(M):
    x, y = heapq.heappop(AA)
    heapq.heappush(AA, [-(y//2), y//2])
AAA = [x[1] for x in AA]
print(sum(AAA))

Submission status: Accepted

Solution code:
import heapq
class PriorityQueue:
	def __init__(self,num_list=None,reverse=False):
		self.reverse = reverse
		self.heap = []
		if num_list != None :
			for num in num_list:
				self.push(num)

	def push(self,num):
		heapq.heappush(self.heap,-num if self.reverse else num)

	def pop(self):
		num = heapq.heappop(self.heap)
		return -num if self.reverse else num
	
	def get_heap(self):
		return list(map(lambda x: x*(-1),self.heap))

n,m = map(int,input().split())
items = list(map(int,input().split()))
pq = PriorityQueue(num_list=items,reverse=True)

while m>0:
	item = pq.pop()
	pq.push(int(item/2))
	m -= 1
print(sum(pq.get_heap()))

Submission status: Accepted

Solution code:
import heapq
class PriorityQueue:
	def __init__(self,num_list=None,reverse=False):
		self.reverse = reverse
		self.heap = []
		if num_list != None :
			for num in num_list:
				self.push(num)

	def push(self,num):
		heapq.heappush(self.heap,-num if self.reverse else num)

	def pop(self):
		num = heapq.heappop(self.heap)
		return -num if self.reverse else num
	
	def get_heap(self):
		return map(lambda x: x*(-1),self.heap)

n,m = map(int,input().split())
items = list(map(int,input().split()))
pq = PriorityQueue(num_list=items,reverse=True)

while m>0:
	item = pq.pop()
	pq.push(int(item/2))
	m -= 1
print(sum(pq.get_heap()))

Submission status: Accepted

Solution code:
from heapq import *
n, m = map(int, input().split())
a = list(map(int, input().split()))


que = []

for v in a:
    heappush(que, -v)

for i in range(m):
    heappush(que, heappop(que) / 2)

print(-sum(int(v) for v in que))

Submission status: Accepted

Solution code:
# 優先度付きキューの考え方が必須
import heapq

N, M = map(int, input().split())
# 読み込み時に * -1 を乗算している
A_list = list(map(lambda x: int(x)*(-1), input().split()))
# A_listを優先度付きキューにする
heapq.heapify(A_list)

while M > 0:
    temp_max = heapq.heappop(A_list)
    # //2 で余りは切り捨てのため -1 を 2回 乗算している
    heapq.heappush(A_list, (-1)*((-1*temp_max)//2))
    M -= 1
print(-1*sum(A_list))

Submission status: Accepted

Solution code:
import heapq

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

for i in range(N):
    A[i]=-1*A[i]

heapq.heapify(A)

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

print(-1*sum(A))

Submission status: Accepted

Solution code:
import heapq
N,M = map(int,input().split())
a = [-i for i in list(map(int,input().split()))]
heapq.heapify(a)
for i in range(M):
    m = heapq.heappop(a)
    heapq.heappush(a,-(-m//2))
print(-sum(a))

Submission status: Accepted

Solution code:
from heapq import heappop,heappush,heapify
n,m=map(int,input().split())
A=list(map(int,input().split()))
A_m=list(map(lambda x: -x,A))
heapify(A_m)
pop=lambda: -heappop(A_m)
push=lambda x: heappush(A_m,-x)
for _ in range(m):
    x=pop()
    push(x//2)
print(-sum(A_m))

Submission status: Accepted

Solution code:
import heapq as hq

n, m = map(int, input().split())
a = list(map(int, input().split()))
h = list(map(lambda x: -x, a))

hq.heapify(h)

for _ in range(m):
    M = hq.heappop(h)
    hq.heappush(h, (M + 1) // 2)

print(-sum(h))

Submission status: Accepted

Solution code:
import heapq

def func(x):
    return -x

def main():
    N, M = map(int, input().split())
    A = list(map(func, map(int, input().split())))
    heapq.heapify(A)

    for _ in range(M):
        tmp = heapq.heappop(A)
        heapq.heappush(A, -(-tmp//2))

    print(-sum(A))



if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import heapq
N,M = map(int,input().split())
l_a = list(map(int,input().split()))
l_a = [(-x,x) for x in l_a]
heapq.heapify(l_a)
for m in range(M):
    if l_a[0][1]%2==1:
        heapq.heappush(l_a,(l_a[0][0]//2+1,l_a[0][1]//2))
    else:
        heapq.heappush(l_a,(l_a[0][0]//2,l_a[0][1]//2))
    heapq.heappop(l_a)
a = 0
for i in range(N):
    a += l_a[i][1]
print(a)

Submission status: Accepted

Solution code:
import heapq
n,m = map(int,input().split())
a = [int(i) * (-1) for i in input().split()]
 
heapq.heapify(a)

for _ in range(m):
	a_min = heapq.heappop(a)
	heapq.heappush(a,(-(-a_min//2)))

print(-sum(a))

Submission status: Accepted

Solution code:
import heapq

N, M = map(int, input().split())
A = [-int(x) for x in input().split()]
heapq.heapify(A)

for _ in range(M):
    tmin = heapq.heappop(A)
    heapq.heappush(A, (-1)*(-tmin//2))

print(-sum(A))

Submission status: Accepted

Solution code:
import heapq
n,m = map(int,input().split())
a = [int(i) * (-1) for i in input().split()]

heapq.heapify(a)

for _ in range(m):
	a_min = heapq.heappop(a)
	heapq.heappush(a,(-(-a_min//2)))

print(-sum(a))

Submission status: Accepted

Solution code:
import heapq
n,m = map(int,input().split())
l = list(map(int,input().split()))

for i in range(n):
  l[i] *= -1

heapq.heapify(l)
for i in range(m):
  new = heapq.heappop(l)
  heapq.heappush(l,-((-new)//2))

print(-sum(l))

Submission status: Accepted

Solution code:
import heapq
import math

n,m = map(int,input().split())
a = [int(i) for i in input().split()]

a = [-1*num for num in a]

heapq.heapify(a)

for i in range(m):
    #1番高い商品の値段を求める
    maximum = heapq.heappop(a)
    #割引券により、半額にする
    add = math.trunc(maximum/2)
    #それをheapqにプッシュする
    heapq.heappush(a,add)

#-1をかけることを忘れずに！
print(-1 * sum(a))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
import heapq
input = lambda: sys.stdin.readline()[:-1]
sys.setrecursionlimit(10**8)

a,m=map(int,input().split())
A=list(map(lambda i:-int(i),input().split()))
heapq.heapify(A)
for i in range(m):
    e=heapq.heappop(A)
    e=(-e)//2
    heapq.heappush(A,-e)
print(-sum(A))

Submission status: Accepted

Solution code:
from heapq import *
n,m = map(int,input().split())
a = list(map(lambda x:-int(x),input().split()))
heapify(a)
for i in range(m):
  heappush(a,-(-heappop(a)//2))
print(-sum(a))

Submission status: Accepted

Solution code:
from heapq import heapify, heapreplace

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

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

for _ in range(M):
    heapreplace(A, -(-A[0]//2))
print(-sum(A))

Submission status: Accepted

Solution code:
import copy
import heapq

def j(n):
    if n:print("Yes")
    else:print("No")
    exit(0)
rem = 10 ** 9 + 7

"""
def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")
"""

def ip():
    return int(input())
def iprow():
    return [int(i) for i in input().split()]
def ips():
    return (int(i) for i in input().split())
def ipmultiplerow(n):
    a = []
    for i in range(n):
        a.append(ip())
    return a
def printrow(a):
    for i in a:
        print(i)

def _heappush_max(heap, item):
    heap.append(item)
    heapq._siftdown_max(heap, 0, len(heap)-1)
def _heappop_max(heap):
    """Maxheap version of a heappop."""
    lastelt = heap.pop()    # raises appropriate IndexError if heap is empty
    if heap:
        returnitem = heap[0]
        heap[0] = lastelt
        heapq._siftup_max(heap, 0)
        return returnitem
    return lastelt


n,m = ips()
a = iprow()
a.sort(reverse=True)
#print(a)
heapq._heapify_max(a)
b = _heappop_max(a)
_heappush_max(a, b)
for i in range(m):
    b = _heappop_max(a)
    #print(b, a)
    b//=2
    _heappush_max(a,b)
print(sum(a))

Submission status: Accepted

Solution code:
import copy
import heapq

def j(n):
    if n:print("Yes")
    else:print("No")
    exit(0)
rem = 10 ** 9 + 7

"""
def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")
"""

def ip():
    return int(input())
def iprow():
    return [int(i) for i in input().split()]
def ips():
    return (int(i) for i in input().split())
def ipmultiplerow(n):
    a = []
    for i in range(n):
        a.append(ip())
    return a
def printrow(a):
    for i in a:
        print(i)

def _heappush_max(heap, item):
    heap.append(item)
    heapq._siftdown_max(heap, 0, len(heap)-1)
def _heappop_max(heap):
    """Maxheap version of a heappop."""
    lastelt = heap.pop()    # raises appropriate IndexError if heap is empty
    if heap:
        returnitem = heap[0]
        heap[0] = lastelt
        heapq._siftup_max(heap, 0)
        return returnitem
    return lastelt


n,m = ips()
a = iprow()
a.sort(reverse=True)
#print(a)
heapq._heapify_max(a)
for i in range(m):
    b = _heappop_max(a)
    #print(b, a)
    b//=2
    _heappush_max(a,b)
print(sum(a))

Submission status: Accepted

Solution code:
import heapq
N, M = map(int, input().split())
A = list(map(int, input().split()))
# print(A)
B = []
for i in range(N):
    heapq.heappush(B,-A[i])
# print(B)
for i in range(M):
    x = -heapq.heappop(B)
    if x == 0:
      break
    x = x//2
    heapq.heappush(B,-x)

# print(B)
print(-sum(B))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
import heapq


class Reverse:
    def __init__(self, val):
        self.val = val

    def __lt__(self, other):
        return self.val > other.val

    def __repr__(self):
        return repr(self.val)


class Heapq:
    def __init__(self, arr, desc=False):
        if desc:
            for i in range(len(arr)):
                arr[i] = Reverse(arr[i])
        self.desc = desc
        self.hq = arr
        heapq.heapify(self.hq)

    def pop(self):
        if self.desc:
            return heapq.heappop(self.hq).val
        else:
            return heapq.heappop(self.hq)

    def push(self, a):
        if self.desc:
            heapq.heappush(self.hq, Reverse(a))
        else:
            heapq.heappush(self.hq, a)

    def top(self):
        if self.desc:
            self.hq[0].val
        else:
            return self.hq[0]


def solve(N: int, M: int, A: "List[int]"):
    hq = Heapq(A, desc=True)
    while M > 0:
        MD = hq.pop()
        M -= 1
        hq.push((MD//2))
        if MD <= 0:
            break
    ans = 0
    while A:
        a = hq.pop()
        ans += a
    print(ans)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, M, A)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

list.sort(A, reverse=True)

while M>0:
    A[0] = int(A[0] / 2)
    #print(A)
    M -= 1
    if M==0:
        break
    for i in range(1,N):
        if(A[i] > A[0]):
            A[i] = int(A[i] / 2)
            #print(A)
            M -= 1
            if M == 0:
                break
        else:
            break
    list.sort(A, reverse=True)


print(sum(A))

Submission status: Accepted

Solution code:
from heapq import heapify, heapreplace
n,m = map(int,input().split())
L = [  -i for i in map(int, input().split())]
heapify(L)
for _ in range(m):
    heapreplace(L,L[0]//2 + L[0]%2)
print(-sum(L))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys


def solve(N: int, M: int, A: "List[int]"):
    while M > 0:
        A = sorted(A, reverse=True)
        MD = A[0] // 2
        for i, ai in enumerate(A):
            if ai > MD and M > 0:
                A[i] = ai//2
                M -= 1
            else:
                break
        if A[i] == 0:
            break
    print(sum(A))
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, M, A)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

while M>0:
  A = sorted(A, reverse=True)
  a_ = A[0]//2
  for i,a_i in enumerate(A):
    if a_i > a_ and M>0:
      A[i] = a_i//2
      M -= 1
    else: break
  if a_==0: break
print(sum(A))

Submission status: Accepted

Solution code:
import heapq

n, m = map(int, input().split())
a = [-int(_) for _ in input().split()]

heapq.heapify(a)

for i in range(m):
    tmp = heapq.heappop(a)
    a.append(tmp / 2)

res_list = [int(-_) for _ in a]
print(sum(res_list))

Submission status: Accepted

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

import heapq
heapq.heapify(lis)
for _ in range(M):
    tmp = -heapq.heappop(lis)
    tmp //= 2
    heapq.heappush(lis,-tmp)

print(-sum(lis))

Submission status: Accepted

Solution code:
#キューを使っている。ところどころマイナスにしているのはキューの性質のため。実行時間が全然違うのはソートが早いから
n,m = map(int,input().split())
a = list(map(lambda x: -int(x) ,input().split()))

import heapq
heapq.heapify(a)
for _ in range(m):
  tmp = -heapq.heappop(a)
  tmp //= 2
  heapq.heappush(a,-tmp)
print(-sum(a))

Submission status: Accepted

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

import heapq
a = [-1*i for i in a]
heapq.heapify(a)
for i in range(M):
    b = heapq.heappop(a)
    b = (-1*b)//2
    heapq.heappush(a, -1*b)
print(-1*sum(a))

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

from heapq import heappop, heappush

n, m = li()
a = list(li())

heap = []

for ai in a:
    heappush(heap, -ai)

for _ in range(m):
    bi = -heappop(heap)
    heappush(heap, -(bi//2))

print(-sum(heap))

Submission status: Accepted

Solution code:
import heapq as hq

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

B = [-i for i in A]
hq.heapify(B)
for i in range(M):
    x = hq.heappop(B)
    hq.heappush(B, -(-x//2))
print(-1*sum(B))

Submission status: Accepted

Solution code:
import heapq

N, M = tuple(map(int, input().split()))
A = list(map(lambda a: -1*int(a), input().split()))
heapq.heapify(A)

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

print(-1*sum(A))

Submission status: Accepted

Solution code:
import heapq
n, m = map(int, input().split())
a = list(map(lambda x: int(x)*(-1), input().split()))
heapq.heapify(a)
for _ in range(m):
    t = heapq.heappop(a)
    heapq.heappush(a, (-1)*(-t//2))
print(-sum(a))

Submission status: Accepted

Solution code:
from heapq import heappush, heappop

N, M = map(int, input().split())
A = list(map(int, input().split()))
pq = []
for a in A:
	heappush(pq, -1*a)

for i in range(M):
	front = heappop(pq)
	front = -1 * front
	front = front // 2
	heappush(pq,-1 * front)

sumi = 0
while True:
	try:
		sumi += (-1 * heappop(pq))
	except Exception as e:
		break;
print(sumi)

Submission status: Accepted

Solution code:
import heapq
n,m = map(int,input().split())
a = [int(x) * -1 for x in input().split()]

a = sorted(a)

for i in range(m):
    off = -1 * heapq.heappop(a) // 2
    heapq.heappush(a,-1*off)

print(-1*sum(a))

Submission status: Accepted

Solution code:
import heapq
N,M=list(map(int,input().split()))
A=list(map(int,input().split()))
A=[-A[i] for i in range(N)]
heapq.heapify(A)
for i in range(M):
    a=A[0]
    heapq.heappop(A)
    heapq.heappush(A,-(a//-2))
print(-sum(A))

Submission status: Accepted

Solution code:
'''
Created on 2019/09/28

@author: oiwaiman
'''

import heapq as hq

N, M = map(int, input().split())
A = list(map(int, input().split()))
B = [-i for i in A]
hq.heapify(B)
for i in range(M):
    a_largest = int((-B[0])/2)
    a_list = hq.heappushpop(B, -a_largest)

sum = 0
for j in range(N):
    sum -= B[j]

print(sum)

Submission status: Accepted

Solution code:
from heapq import heappop, heappush
heap = []
N, M = map(int, input().split())
for i in list(map(int,input().split())):
    heappush(heap, i*-1)
for j in range(M):
    num = -((-heappop(heap))//2)
    heappush(heap, num)

print(sum(heap) * - 1)

Submission status: Accepted

Solution code:
import heapq
n, m = map(int, input().split())
A = list(map(lambda x: int(x)*-1, input().split()))
heapq.heapify(A)

for i in range(m):
  max_elm = heapq.heappop(A)*-1 //2
  heapq.heappush(A, max_elm*-1)

print(sum(A)*-1)

Submission status: Accepted

Solution code:
import heapq

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

heapq.heapify(A)

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

ans = 0
for a in A:
    ans -= int(a)

print(ans)

Submission status: Accepted

Solution code:
from heapq import*
from math import*
n,m,*a=map(int,open(0).read().split())
a=[-i for i in a]
heapify(a)
for i in range(m):
    heappush(a,-((-heappop(a))//2))
print(-sum(a))

Submission status: Accepted

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

import heapq
heapq.heapify(A)

for ticket_num in range(1,M+1):
    max_value = -1*heapq.heappop(A)
    heapq.heappush(A, -1*(max_value>>1))

print(-1*sum(A))

Submission status: Accepted

Solution code:
import heapq
n, m = map(int, input().split())
a = list(map(int, input().split()))
for i in range(n):
    a[i] *= -1
heapq.heapify(a)
for _ in range(m):
    x = heapq.heappop(a)
    heapq.heappush(a, (-x//2)*(-1))    
 
print(-sum(a))