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:
import heapq
n,m = map(int,input().split())
a_list=[-int(s) for s in input().split()]
heapq.heapify(a_list)

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

print(-sum(a_list))

Submission status: Accepted

Solution code:
import heapq
N,M=map(int,input().split())
kakaku=list(map(int,input().split()))
han=[]
for i in range(N):
  han.append(-kakaku[i])
  
heapq.heapify(han)
for _ in range(M):
  k=heapq.heappop(han)
  k=k/2
  heapq.heappush(han,k)

sum=0
for j in range(N):
  sum+=int(-han[j])
print(sum)

Submission status: Accepted

Solution code:
import heapq

def main():

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

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

    for i in range(n):
        sum += a[i]

    print(-sum)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/python3

import heapq
import math
import sys


DEBUG = False


def inp():
    return sys.stdin.readline().rstrip()


def dprint(*value, sep=' ', end='\n'):
    if DEBUG:
        print(*value, sep=sep, end=end)


def solve(N, M, A):
    hq = [-a for a in A]
    heapq.heapify(hq)
    for _ in range(M):
        v = -hq[0]
        if v < 1:
            break
        v //= 2
        heapq.heapreplace(hq, -v)

    return sum([math.floor(-v) for v in hq])


def main():
    N, M = [int(e) for e in input().split()]
    A = [int(e) for e in input().split()]
    print(solve(N, M, A))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import heapq

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

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

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

Submission status: Accepted

Solution code:
import heapq

n=list(map(int,input().split()))
m=list(map(int,input().split()))
m = [-x for x in m]
heapq.heapify(m)

for i in range(n[1]):
  x=(-1*m[0])//2
  heapq.heappop(m)
  heapq.heappush(m, -x)

ans=0
for i in range(n[0]):
  ans+=-m[i]

print(ans)

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)

while M:
  m = heapq.heappop(A) * (-1)
  heapq.heappush(A, (-1) * (m // 2))
  M -= 1
print (sum(A) * (-1))

Submission status: Accepted

Solution code:
import math
import heapq

n, m =map(int,input().split()) 
a =list(map(int, input().split()))
h =[]
for i in a:
    heapq.heappush(h, i*(-1))


while m >0:
    heru = math.ceil((heapq.heappop(h))/2)
    heapq.heappush(h,heru)
    m = m-1
print((-1)*sum(h))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-


def main():
    from heapq import heappush, heappop

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

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

    for i in range(m):
        bi = -heappop(b)
        bi //= 2
        heappush(b, -bi)

    print(-sum(b))


if __name__ == '__main__':
    main()

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]=-a[i]
heapq.heapify(a)

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

for i in range(n):
    a[i]=-a[i]

print(sum(a))

Submission status: Accepted

Solution code:
import heapq

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

def minus_int(x):
  return -1 * int(x)

a = list(map(minus_int, input().split()))
heapq.heapify(a)

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

Submission status: Accepted

Solution code:
import sys
import math
from fractions import gcd
# import queue
# from collections import Counter
# from itertools import accumulate
# from functools import reduce

def lcm(a, b):
    return a * b // gcd(a, b)

def combination_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

big_prime = 1000000007

"""
# 標準入力取得
## 文字列
 =  sys.stdin.readline().rstrip()
 =  list(sys.stdin.readline().rstrip())

## 数値
 =  int(sys.stdin.readline())
 =  map(int, sys.stdin.readline().split())
 =  list(map(int, sys.stdin.readline().split()))
 =  [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
"""
from heapq import heappop, heappush, heapify
n,m =  map(int, sys.stdin.readline().split())
a =  list(map(int, sys.stdin.readline().split()))
q = []

for x in a:
        heappush(q,-x)
for _ in range(m):
        l = heappop(q)# 最小値をヒープから取り出す
        heappush(q, -((-l)//2))
print(-sum(q))

Submission status: Accepted

Solution code:
from heapq import heapify, heappop, heappush

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

heapify(A)
for i in range(M):
    heappush(A, int(heappop(A) / 2))

print(-1 * sum(A))

Submission status: Accepted

Solution code:
import sys
import numpy as np
import math
import heapq
def input():
    return sys.stdin.readline()[:-1]

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

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

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

Submission status: Accepted

Solution code:
import heapq

NM =input().split(" ")
A_LIST = input().split(" ")
N = int(NM[0])
M = int(NM[1])

A = []
for i in A_LIST:
    heapq.heappush(A, -1 * int(i))
    
for i in range(0, M):
    m = heapq.heappop(A)
    m = -1 * m
    m = m // 2
    heapq.heappush(A, -1 * m)

S = 0    
for i in A:
    S += (-1 * i)

print(S)

Submission status: Accepted

Solution code:
import heapq

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

heapq.heapify(price)
# print(price)
for i in range(m):
    # print(i+1)
    a = int(heapq.heappop(price)/2)
    heapq.heappush(price,a)
    # print(price)
print(-sum(price))

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] = a[i]*(-1)
heapq.heapify(a)
for i in range(m):
    b = heapq.heappop(a)
    if b % 2 == 0:
        b = b //2
    else:
        b = b//2 + 1
    #print(b)
    heapq.heappush(a,b)
ans = 0
for i in range(n):
    ans += (heapq.heappop(a))*(-1)
print(ans)

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):
    y = heapq.heappop(a)
    heapq.heappush(a, (-1)*(-y//2))

print(-sum(a))

Submission status: Accepted

Solution code:
import heapq


N,M = [int(i) for i in input().split()]
data = [int(i) for i in input().split()]
data = list(map(lambda x: x*(-1), data))
heapq.heapify(data)
#print(data)
while M != 0:
    x = heapq.heappop(data)*(-1)
    heapq.heappush(data,-1*(x//2))
    M -= 1
    #print(data)
 
print(-sum(data))

Submission status: Accepted

Solution code:
def main():
    from heapq import heappush,heappop,heapify
    N, M = (int(i) for i in input().split())
    A = [-int(i) for i in input().split()]
    heapify(A)
    for divcnt in range(M):
        tmp = -heappop(A)
        tmp //= 2
        heappush(A,-tmp)
    print(-sum(A))
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from heapq import heappush,heappop,heapify
from math import ceil
def main():
    N, M = (int(i) for i in input().split())
    A = [-int(i) for i in input().split()]
    heapify(A)
    for divcnt in range(M):
        tmp = ceil(heappop(A)/2)
        heappush(A,tmp)
    print(-sum(A))
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10000000)
def input():
    return sys.stdin.readline()[:-1]
from bisect import *
from collections import *
from heapq import *
from math import *
from itertools import *
INF = 10**10

N, M = map(int, input().split())
h = [-int(x) for x in input().split()]
heapify(h)
for i in range(M):
    x = -heappop(h)//2
    heappush(h, -x)
print(-sum(h))

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)

# 以下を割引券の枚数分繰り返す
# 最も高い品物に割引券を1枚使う
for _ in range(M):
	min = heapq.heappop(A)
	heapq.heappush(A, (-1) * (-min // 2))

print(-sum(A))

Submission status: Accepted

Solution code:
import heapq


def main():
    n, m = map(int, input().split(' '))
    a_s = list(sorted(map(lambda x: -1 * int(x), input().split(' '))))

    heapq.heapify(a_s)
    for _ in range(m):
        e = heapq.heappop(a_s)
        heapq.heappush(a_s, int(e/2))
    print(-1*sum(a_s))
    
    

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
import heapq

input = sys.stdin.readline

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

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

minus = lambda x:-x

data = list(map(minus,data))
#print(data)

heapq.heapify(data)
#print(data)

for i in range(M):
    x = heapq.heappop(data)
    x = - (abs(x) // 2)
    heapq.heappush(data,x)
    #print(data)

print(-sum(data))

Submission status: Accepted

Solution code:
import heapq

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

heapq.heapify(A)

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

print(-sum(A))

Submission status: Accepted

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

import heapq

h = []
for i in range(N):
    heapq.heappush(h, A[i]*(-1))
    
for i in range(M):
    temp = heapq.heappop(h)
    temp *= (-1)
    temp //= 2
    temp *= (-1)
    heapq.heappush(h, temp)
    
print(sum(h)*(-1))

Submission status: Accepted

Solution code:
import heapq
N,M=map(int,input().split())
A=[int(i) for i in input().split()]
q=[]
for i in range(N):
    heapq.heappush(q,-A[i])
for i in range(M):
    K=-heapq.heappop(q)
    L=K//2
    heapq.heappush(q,-L)
ans=0
for i in range(N):
    ans-=heapq.heappop(q)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import heapq
 
def FUNCTION(A, M):
    heapq.heapify(A)
    for i in range(M):
        heapq.heappush(A, int(heapq.heappop(A) / 2))
    return -sum(A)

N = list(map(int, (input().split(' '))))
A = list(map(lambda x: x*(-1), map(int, (input().split(' ')))))
print(FUNCTION(A, N[1]))

Submission status: Accepted

Solution code:
import heapq

n, m = list(map(int, input().split()))
A = [int(x) * -1 for x in input().split()]
heapq.heapify(A)

ans = 0
for _ in range(m):
    tmp_max = -(-1 * heapq.heappop(A) // 2)
    heapq.heappush(A, tmp_max)

for i in range(n):
    ans += heapq.heappop(A) * (-1)

print(ans)

Submission status: Accepted

Solution code:
def solve(string):
    n, m, *a = map(int, string.split())
    while m > 0:
        a.sort(reverse=True)
        if a[0] == 0:
            break
        b = a[0] // 2
        for i, _a in enumerate(a):
            if m == 0 or _a <= b:
                break
            a[i] //= 2
            m -= 1
    return str(sum(a))


if __name__ == '__main__':
    print(solve('\n'.join([input(), input()])))

Submission status: Accepted

Solution code:
from heapq import heappush, heappop


def solve(string):
    n, m, *a = map(int, string.split())
    while m > 0:
        a.sort(reverse=True)
        if a[0] == 0:
            break
        b = a[0] // 2
        for i, _a in enumerate(a):
            if m == 0 or _a <= b:
                break
            a[i] //= 2
            m -= 1
    return str(sum(a))


if __name__ == '__main__':
    print(solve('\n'.join([input(), input()])))

Submission status: Accepted

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

ans = 0
for i in a:
    ans += int(i)

print(-ans)

Submission status: Accepted

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

while m != 0 :
    arr.sort(reverse=True)
    j = arr[0] // 2
    for i in range(l):
            if arr[i] > j:
                if m != 0:
                    m -= 1
                else:
                    break
                arr[i] //= 2
            else:
                break
    if arr[0] == 0:
        break
            

print(sum(arr))

Submission status: Accepted

Solution code:
import heapq

N,M = map(int,input().split())
#lst = list(map(int,input().split()))
lst = [-int(x) for x in input().split()]

heapq.heapify(lst)
 
for i in range(M):
    lstmin = heapq.heappop(lst)
    b = (-(lstmin) // 2)
    heapq.heappush(lst,-b)
    
print (-sum(lst))

Submission status: Accepted

Solution code:
from heapq import heappush, heappop


def solve(string):
    n, m, *a = map(int, string.split())
    h = []
    for _a in a:
        heappush(h, -_a)
    for _ in range(m):
        heappush(h, -(-heappop(h) // 2))
    return str(-sum(h))


if __name__ == '__main__':
    print(solve('\n'.join([input(), input()])))

Submission status: Accepted

Solution code:
# 最小金額を求める
# 一番高い商品に割引を適用して半額（小数点以下切り捨て）にする作業の繰り返し
# 問題詳細：https://atcoder.jp/contests/abc141/tasks/abc141_d
# 優先度付きキューを利用する
import heapq

def main():
  n, m = map(int, input().split())
  a = list(map(int, input().split()))
  pq = to_priorityqueue(a)
  pq = use_ticket(pq, m)
  print(-sum(pq))


# 優先度付きキューを作成
# heapqモジュールを利用
# pythonのheapqの場合、pop(取り出し)を行った際に最小のものから取り出される
# 今回は大きい順に取り出して利用したいため、-1を掛けてpushする（最大の値が最小になる）
def to_priorityqueue(list):
  rtn = []
  for el in list:
    heapq.heappush(rtn, -el)
  return rtn

# チケットの利用（割引の適用）
# チケットがなくなるまで、その時点で最も価格が高い商品にわりびきを適用する
# 最大まで割引を適用した結果できたキューを返す
def use_ticket(pq, t_num):
  while t_num and pq:
    el = -(heapq.heappop(pq))
    el //= 2
    heapq.heappush(pq, -el)
    t_num -= 1
  return pq

if __name__ == "__main__":
  main()

Submission status: Accepted

Solution code:
import heapq

N, M  = [int(x) for x in input().split()]
l = [-int(x) for x in input().split()]
heapq.heapify(l)
for i in range(M):
  h = heapq.heappop(l)
  h = -h // 2
  heapq.heappush(l, -h)
print(-sum(l))

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] = -A[i]

heapq.heapify(A)

for j in range(M):
    a = heapq.heappop(A)
    b = -1*((-a) // 2)
    heapq.heappush(A,b)

print(-sum(A))

Submission status: Accepted

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

heap = []
for i in a:
    heapq.heappush(heap, -i)


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



print(sum(map(lambda n: int (-n), heap)))

Submission status: Accepted

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

heap = []
for i in a:
    heapq.heappush(heap, -i)


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



print(sum(map(lambda n: int (-n), heap)))

Submission status: Accepted

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

while m > 0 and a[0] > 0:
    a.sort(reverse=True)
    tmp = a[0] // 2
    for i in range(n):
        if a[i] > tmp and m > 0:
            a[i] //= 2
            m -= 1
        else:
            break

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)

#heappopは最小の値（一番上のノードの値を返す)
for _ in range(m):
    tmp = int(heapq.heappop(a)/2)
    #新しい値(2で割った値)を挿入してヒープを保つ)
    heapq.heappush(a,tmp)

print(-sum(a))

Submission status: Accepted

Solution code:
import sys
import heapq

n, m = map(int, sys.stdin.readline().split())

a = list(map(int, sys.stdin.readline().split()))

pq = []

for ele in a:
	heapq.heappush(pq, -ele)

while m and pq:
	ele = -(heapq.heappop(pq))
	ele = ele//2
	if ele:
		heapq.heappush(pq, -ele)
	m -= 1
print(-sum(pq))

Submission status: Accepted

Solution code:
import heapq
n,m=[int(i) for i in input().split()]
a=[int(i) for i in input().split()]
heap=[]
for i in a:
    heapq.heappush(heap,10**5-i)

for i in range(m):
    tmp=heapq.heappop(heap)
    tmp=(10**5-tmp)//2
    heapq.heappush(heap,10**5-tmp)

ans=0
for i in range(n):
    ans+=10**5-heap[i]
print(ans)

Submission status: Accepted

Solution code:
'use strict'
import heapq

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

heapq.heapify(goods_price_list)

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

print(-sum(goods_price_list))

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):
  tmp_min = heapq.heappop(a)
  heapq.heappush(a, (-1)*(-tmp_min//2))
print(-sum(a))

Submission status: Accepted

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

A = [-a for a in A]

from heapq import heapify, heappop, heappush

heapify(A)

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

Submission status: Accepted

Solution code:
from queue import PriorityQueue

N, M = map(int, input().split())
A = list(map(int, input().split()))
queue = PriorityQueue()
for a in A:
    queue.put(-a)
for _ in range(M):
    v = -queue.get()
    queue.put(-(v // 2))

total = 0
while not queue.empty():
    total += -(queue.get())
print(total)

Submission status: Accepted

Solution code:
import heapq

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

def pop():
    return -heapq.heappop(a)

def push(x):
    return heapq.heappush(a, -x)

for _ in range(m):
    tmp = pop()
    push(tmp//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):
    tmp = -heapq.heappop(a) // 2
    heapq.heappush(a, -tmp)

print(-sum(a))

Submission status: Accepted

Solution code:
import heapq

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

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

print(-sum(a))

Submission status: Accepted

Solution code:
import heapq
n,m=map(int,input().split())
a=list(map(int,input().split()))
lis=[]
for i in range(n):
    heapq.heappush(lis,-a[i])
for i in range(m):
    b=(heapq.heappop(lis)*(-1)//2)*(-1)
    heapq.heappush(lis,b)
    #print(lis)
ans=0
#print(lis)
for i in range(n):
    ans+=lis[i]
print(-ans)

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 i in range(m):
    tmp = (heapq.heappop(a) * (-1)) // 2
    heapq.heappush(a, tmp * (-1))

print(sum(a) * (-1))

Submission status: Accepted

Solution code:
import heapq
def f(s):
  return -int(s)
N,M = map(int,input().split())
A = list(map(f,input().split()))

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

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

Submission status: Accepted

Solution code:
import heapq

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

heapq.heapify(A)
for i in range(N[1]):
    heapq.heappush(A, int(heapq.heappop(A) / 2))

print(-sum(A))

Submission status: Accepted

Solution code:
n,m = map(int, input().split())
def intm(x):
  return int(x)*-1
a = list(map(intm, input().split()))

import heapq

heapq.heapify(a)

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

Submission status: Accepted

Solution code:
import heapq

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

heapq.heapify(A)

for _ in range(M):
    b = -heapq.heappop(A)//2
    #print(b)
    heapq.heappush(A,-b)
print(-sum(A))

Submission status: Accepted

Solution code:
import heapq,math
n, m = map(int, input().split())
a =[int(i) *(-1) for i in input().split()]
heapq.heapify(a)
for _ in range(m):
    amin = heapq.heappop(a)
    heapq.heappush(a, amin/2)
ans = 0
for _a in a:
    ans += math.floor(_a * (-1))
print(ans)

Submission status: Accepted

Solution code:
import heapq

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

heapq.heapify(A)

for m in range(M):
    heapq.heapreplace(A, -(-A[0] // 2))

print(-sum(A))

Submission status: Accepted

Solution code:
from heapq import heappushpop, heappush, heappop, heapify
N, M = map(int, input().split())
a = [-int(a) for a in input().split()]
heapify(a)
t = heappop(a) / 2
for _ in range(M - 1):
  t = heappushpop(a, t) / 2
heappush(a, t)
print(sum(int(-x) for x in a))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/python3

from fractions import Fraction
import heapq
import math
import sys


DEBUG = False


def inp():
    return sys.stdin.readline().rstrip()


def dprint(*value, sep=' ', end='\n'):
    if DEBUG:
        print(*value, sep=sep, end=end)


def solve(N, M, A):
    hq = [-a for a in A]
    heapq.heapify(hq)
    for _ in range(M):
        v = -hq[0]
        if v < 1:
            break
        v = Fraction(v, 2)
        heapq.heapreplace(hq, -v)

    return sum([math.floor(-v) for v in hq])


def main():
    N, M = [int(e) for e in input().split()]
    A = [int(e) for e in input().split()]
    print(solve(N, M, A))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import heapq
n,m = [int(i) for i in input().split()]
l = [int(i) for i in input().split()]
h = []
for i in l:
    i = -1*i
    heapq.heappush(h,i)
    
for _ in range(m):
    v = -heapq.heappop(h)
    heapq.heappush(h,-1*(v//2))
    
print(-sum(h))

Submission status: Accepted

Solution code:
import heapq as hp

n,m=map(int,input().split())
a=list(map(lambda x: -x ,map(int,input().split())))
hp.heapify(a)
for _ in range(m):
    tmp=hp.heappop(a)
    tmp//=-2
    hp.heappush(a,-tmp)
print(-sum(a))

Submission status: Accepted

Solution code:
import heapq

N,M=map(int,input().split())
A=list(map(int,input().split()))
#print(A)
A =[-a for a in A]
#print(A)
heapq.heapify(A)

for w in range(M):
    max=heapq.heappop(A)
    heapq.heappush(A,max/2)
   
B=list(map(int, A))
#print(B)
print(sum(B)*-1)

Submission status: Accepted

Solution code:
import heapq as hq

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

A = []
for a in [int(_) for _ in input().split()]:
    hq.heappush(A, -a)

for _ in range(m):
    t = hq.heappop(A)
    hq.heappush(A, t / 2)
print(-sum([int(a) for a in A]))

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(int(1e6))

import heapq

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

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

prices = [- heapq.heappop(h_A) for _ in range(N)]
print(sum(prices))

Submission status: Accepted

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

hq.heapify(A)
for i in range(M):
    m = A[0]
    hq.heappushpop(A, -((-m)//2))
print(-sum(A))

Submission status: Accepted

Solution code:
import heapq

def solve(n, m, a):
    v = []
    for i in range(n):
        heapq.heappush(v, -a[i])
    for i in range(m):
        x = heapq.heappop(v)
        x /= 2
        heapq.heappush(v, x)
    res = sum([int(-heapq.heappop(v)) for i in range(n)])
    return int(res)

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

Submission status: Accepted

Solution code:
import sys
import heapq

input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

N, M = map(int, input().split())
# マイナスを掛け最大値を優先順位にする
A = list(map(lambda x: int(x)*(-1), input().split()))
heapq.heapify(A) # 優先度付きキューに変換

for _ in range(M):
  max_q = -heapq.heappop(A) # 最大値pop
  heapq.heappush(A, -(max_q//2)) # 最大値を割りリストに戻す
  
print(-sum(A))  # マイナスを掛け値を元に戻す

Submission status: Accepted

Solution code:
import heapq

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

heapq.heapify(A)

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

A = [-val for val in A]

print(sum(A))

Submission status: Accepted

Solution code:
import heapq

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

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

print(-sum(queue))

Submission status: Accepted

Solution code:
import heapq

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

heapq.heapify(a)
for t in range(m):
  discount = heapq.heappop(a) / 2.
  heapq.heappush(a, discount)
    
print(sum(map(lambda x: int(-x), a)))

Submission status: Accepted

Solution code:
import heapq
N,M=[int(s) for s in input().split()]
ls=input().split()
h = []
for e in ls:
  heapq.heappush(h, -int(e))
for i in range(M):
  x=heapq.heappop(h)
  y=(-x)//2
  heapq.heappush(h,-y)
print(-sum(h))

Submission status: Accepted

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

heapq.heapify(A)
  
for i in range(M):
  curr = -heapq.heappop(A)
  heapq.heappush(A, -(curr//2))
  
print(-sum(A))

Submission status: Accepted

Solution code:
import heapq

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

heap = [-Ai for Ai in A]
heapq.heapify(heap)
for _ in range(M):
    heapq.heapreplace(heap, heap[0]/2)
A = [int(-p) for p in heap]
print(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):
  temp=(-1)*heapq.heappop(A)>>1
  heapq.heappush(A, temp*(-1))
print(-sum(A))

Submission status: Accepted

Solution code:
import heapq
import math

q = []
N, M = map(int, input().split())
A = list(map(int, input().split()))
for i in A:
    heapq.heappush(q, -i)
for j in range(M):
    x = heapq.heappop(q)
    heapq.heappush(q, math.ceil(x/2))
print(-sum(q))

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 i in range(M):
  v = heapq.heappop(A) # 最大値をpop
  heapq.heappush(A,-(-v//2)) # 最大値を切り捨て半額にしてpush
  
print(-sum(A)) # 正負を戻す

Submission status: Accepted

Solution code:
import sys
import heapq
import numpy as np
input=sys.stdin.readline

n,m=map(int, input().split())
a=list(map(int, input().split()))
h=[]
for val in a:
    heapq.heappush(h, -val)

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

print(-sum(h))

Submission status: Accepted

Solution code:
import heapq
N,M=[int(s) for s in input().split()]
ls=[int(s) for s in input().split()]
h = []
for e in ls:
  heapq.heappush(h, (-e,e))
for i in range(M):
  x=heapq.heappop(h)
  y=x[1]//2
  heapq.heappush(h,(-y,y))
ls2=[e[1] for e in h]
print(sum(ls2))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import heapq
n, m = [int(x) for x in input().split()]
prices = [-int(x) for x in input().split()]
heapq.heapify(prices)

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

print(abs(sum(prices)))

Submission status: Accepted

Solution code:
import heapq

m = list(map(int,input().split()))
a = list(map(int,input().split()))
for i in range(len(a)):
  a[i] = a[i]*-1

heapq.heapify(a)

for i in range(m[1]):
     k= heapq.heappop(a)
     heapq.heappush(a, -(-k//2))

print(sum(a)*-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 _ in range(m):
    tmp = ((-1)*heapq.heappop(a))//2
    heapq.heappush(a, (-1)*tmp)
print(-sum(a))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

import heapq

def ans() :
    n, m  = map(int, input().split())
    aa = map(int, input().split())
    a = []
    for i in aa:
        heapq.heappush(a, int(i) * (-1))

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

    print(-sum(a))

if __name__ == '__main__':
    ans()

Submission status: Accepted

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

pq = []
for a in A:
    heapq.heappush(pq, -a)#'-'にすることで最大値を考えることができる！
#print(pq)
for _ in range(m):
    a = (-heapq.heappop(pq)) // 2
    heapq.heappush(pq, -a)
print(-sum(pq))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import heapq

N, M = map(int, input().split())
A = [-i for i in map(int, input().split())]
heapq.heapify(A)
for i in range(M):
  tmp = -((-heapq.heappop(A))//2)
  heapq.heappush(A, tmp)

print(-sum(A))