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: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
a = list(map(float, input().split()))
ans = 0
for i in range(m):
    max_idx = a.index(max(a))
    a[max_idx] /= 2
for i in range(n):
    ans += int(a[i])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
a = sorted(list(map(int, input().split())), reverse=True)

if n == 1:
    while m > 0:
        a[0] //= 2
        m -= 1
    print(a[0])
    exit()

while m > 0:
    a[0] //= 2
    m -= 1
    if a[0] < a[1]:
        a.sort(reverse = True)
print(sum(a))

Submission status: Time Limit Exceeded

Solution code:
from bisect import insort

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

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

a.sort()

for _ in range(m):
    max_product = a.pop(-1)
    max_product //= 2
    insort(a,  max_product)
print(sum(a))

Submission status: Time Limit Exceeded

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

count = 0
while count < M:
    As.sort(reverse=True)
    As[0] = int(As[0]/2)
    count += 1

print(sum(As))

Submission status: Time Limit Exceeded

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

for i in range(m):
  a.sort()
  t=int(a.pop(-1)/2)
  a.append(t)
print(sum(a))

Submission status: Time Limit Exceeded

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

A.sort(reverse=True)

for i in range(M):
    a=A[0]//2
    del A[0]
    flag=True
    for j in range(N-1):
        #print(A,a,A[j])
        if A[j]<a:
            A.insert(j,a)
            #print('inserted',A)
            flag=False
            break
    if flag:
        A.insert(N-1,a)
        #print('inserted',A)

sum=0
for i in range(N):
    sum+=A[i]
print(sum)

Submission status: Time Limit Exceeded

Solution code:
N,M=map(int,input().split())
List = list(map(int,input().split()))
for i in range(M):
    MaxY = max(List) 
    Y = List.index(MaxY)
    List[Y] = MaxY //2
Sum = 0
for j in range(N):
    Sum += List[j]
print(Sum)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
import math
import fractions

n, m = [int(x) for x in stdin.readline().rstrip().split()]
a = [int(x) for x in stdin.readline().rstrip().split()]

a.sort(reverse=True)

for i in range(m):
    a[0] = int(a[0]/2)
    a.sort(reverse=True)

print(sum(a))

Submission status: Time Limit Exceeded

Solution code:
import heapq

def max_heappop(a):
  b = list(map(lambda x:x*(-1), a))
  heapq.heapify(b)
  pop_val = -heapq.heappop(b)
  a = list(map(lambda x:x*(-1), b))
  heapq.heapify(a)
  return pop_val,a

def main():
  N,M = map(int, input().split())
  An = list(map(int, input().split()))
  
  heapq.heapify(An)
  
  for _ in range(M):
    max_val,An = max_heappop(An)
    heapq.heappush(An, max_val//2)
  
  print(sum(An))
  
if __name__ == '__main__':
  main()

Submission status: Time Limit Exceeded

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

def discount(l):
  l[-1] = l[-1] // 2
  l.sort()

for i in range(M):
  discount(A)
  
print(sum(A))

Submission status: Time Limit Exceeded

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

A.sort()
for i in range(M):
  A[-1] = A[-1] // 2
  A.sort()
  
print(sum(A))

Submission status: Time Limit Exceeded

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

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

if N == 1:
    MAX = A[0]//2**M 
    print(MAX)
    exit()

while M > 0:
    MAX = max(A)
    A.remove(MAX)
    A.append(MAX//2)

    M -= 1

print(sum(A))

Submission status: Time Limit Exceeded

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

N, M = map(int, input().split())
A = sorted(list(map(int, input().split())))[::-1]

if N == 1:
    print(A[0]//2**M)
    exit()

cnt = 0
while M > 0:
    m = 1
    while True:
        if A[0]//2**m < A[1]:
            break
        else:
            m += 1
    if M-m >= 0:
        A.append(A[0]//2**m)
        M -= m
        cnt += m
    else:
        A.append(A[0]//2**M)
        M = 0
        cnt += M
    A.pop(0)
    A = sorted(A)[::-1]

print(sum(A))

Submission status: Time Limit Exceeded

Solution code:
co = list(map(int,input().split()))
A = list(map(int,input().split()))
N = co[0]
M = co[1]
A.sort()
A.reverse()
for i in range(M):
    
    A[0] //= 2
    for j in range(N-1):
        if A[j] > A[j+1]:
            break
        A[j], A[j+1] = A[j+1], A[j]
print(sum(A))

Submission status: Time Limit Exceeded

Solution code:
co = list(map(int,input().split()))
A = list(map(int,input().split()))
N = co[0]
M = co[1]
A.sort()
A.reverse()
for i in range(M):
    
    A[0] //= 2
    A.sort()
    A.reverse()
print(sum(A))

Submission status: Time Limit Exceeded

Solution code:
co = list(map(int,input().split()))
A = list(map(int,input().split()))
N = co[0]
M = co[1]
for i in range(M):
    A.sort()
    A.reverse()
    A[0] //= 2
    A.sort()
    A.reverse()
print(sum(A))

Submission status: Time Limit Exceeded

Solution code:
import os
import math

def main():
	n,m = map(int, input().split())
	a_list = list(map(int, input().split()))
	a_list.sort(reverse=True)
	
	for i in range(m):
		max_num = a_list[0]
		a_list[0] = math.floor(max_num/(2))
		a_list.sort(reverse=True)
	print(sum(a_list))
		

if __name__ == "__main__":
	main()

Submission status: Time Limit Exceeded

Solution code:
def solve():
    n, m = map(int, input().split())
    a = sorted(list(map(int, input().split())))
    # 最大の値でチケットを使う
    # まだ最大かどうか考慮Y：もう一度使うN:バイナリーサーチをかけてリストをソートする
    for i in range(m):
        a[len(a)-1] //= 2
        if a[len(a)-1] < a[len(a)-2]:
            a = binary_search(a, a[len(a)-1])
    return sum(a)


def binary_search(lst, num):
    lst.pop(len(lst)-1)
    left, right = 0, len(lst)-1
    while left <= right:
        mid = (left + right)//2
        if lst[mid] < num:
            left = mid + 1
        else:
            right = mid-1
    lst.insert(mid, num)
    return lst


ans = solve()
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n,m=map(int,input().split())
a=list(map(int,input().split()))
a=np.array(a)
a=np.sort(a)
for i in range(m):
  a[-1]=a[-1]//2
  a=np.sort(a)
print(sum(a))

Submission status: Time Limit Exceeded

Solution code:
n,m=map(int,input().split())
a=list(map(int,input().split()))
a=sorted(a)
for i in range(m):
  a[-1]=a[-1]//2
  a=sorted(a)
print(sum(a))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import math

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


total = sum(A)
for i in range(M):
    max_index = np.argmax(A)
    total -= math.ceil(A[max_index] / 2)
    A[max_index] = A[max_index] // 2

print(total)

Submission status: Time Limit Exceeded

Solution code:
from bisect import insort_left
N,M = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
for i in range(M):
    A[-1] = A[-1]/2
    k = A[-1]
    A = A[:-1]
    insort_left(A,k)
s = 0
for i in range(N):
    s += int(A[i])
print(s)

Submission status: Time Limit Exceeded

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

for i in range(M):
    A[0] = A[0]//2
    A.sort(reverse = True)

print(sum(A))

Submission status: Time Limit Exceeded

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

A.sort()
A.reverse()

for _ in range(m):
    temp = A.pop(0)//2
    A.append(temp)
    A.sort()
    A.reverse()

print(sum(A))

Submission status: Time Limit Exceeded

Solution code:
N,M=map(int,input().split())
A=sorted(list(map(int,input().split())))
for i in range(M):
  A.sort()
  A[-1]=A[-1]//2
print(sum(A))

Submission status: Time Limit Exceeded

Solution code:


n,m=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
b=[0]*m
for _ in range(m):
    if b[-1:]<a[-1:]:
        temp=a.pop()
    else:
        temp=b.pop()
    temp=temp//2
    b[0]=temp
    b.sort()

print(sum(a)+sum(b))

Submission status: Time Limit Exceeded

Solution code:
n,m=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
b=[0]
for i in range(m):
    if b[-1:]<a[-1:]:
        temp=a.pop()
    else:
        temp=b.pop()
    temp=temp//2
    b.append(temp)
    b.sort()

print(sum(a)+sum(b))

Submission status: Time Limit Exceeded

Solution code:
n,m=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
for i in range(m):
    temp=a.pop()
    temp=temp//2
    a.append(temp)
    a.sort()
print(sum(a))

Submission status: Time Limit Exceeded

Solution code:
from bisect import insort

N,M = map(int,input().split())
A = list(map(int,input().split()))
A.sort(reverse=True)
for i in range(M):
    X = max(A)
    insort(A,X//2)
    A.remove(X)
print(sum(A))

Submission status: Time Limit Exceeded

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

for i in range(M):
    mx = max(As)
    As[As.index(mx)] = mx//2

print(sum(As))

Submission status: Time Limit Exceeded

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
for i in range(k):
    s=max(a)//2
    j=a.index(max(a))
    a[j]=s
print(sum(a))

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import permutations,combinations
from collections import defaultdict,Counter
from bisect import bisect_left,bisect_right
# from math import gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint

def myinput():
    return map(int,input().split())

def mylistinput(n):
    return [ list(myinput()) for _ in range(n) ]

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse_flag):
    data.sort(key=lambda x:x[col],reverse=reverse_flag)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

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

# a.sort()

for i in range(m):
    M = max(a)
    ind = a.index(M)
    a[ind] = M//2
# print(a)
ans = sum(a)
print(ans)

Submission status: Time Limit Exceeded

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

import math
for i in range(m):
    a.sort(reverse = True)
    a[0] = a[0]/2

import math
print(sum(list(map(math.floor,a))))

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
q = deque(a)

count_use = 0
while count_use < m:
    max_a = a.pop()
    max_a = max_a//2
    a.append(max_a)
    a.sort()
    count_use += 1

print(sum(a))

Submission status: Time Limit Exceeded

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

count_use = 0
while count_use < m:
    max_a = max(a)
    a[a.index(max_a)] = max_a//2
    count_use += 1

print(sum(a))

Submission status: Time Limit Exceeded

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

for _ in range(M):
    A.sort(reverse=True)
    A[0] //= 2

print(sum(A))

Submission status: Time Limit Exceeded

Solution code:
def main():
    n, m = map(int, input().split())
    a = list(map(int, input().split()))
    a = sorted(a)
    for i in range(m):
        a[-1] //= 2
        a.sort()
    print(sum(a))


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
N,M=map(int,input().split())
price_list=sorted([int(item) for item in input().split()])
total_m=0
def discount(price_list,tickets_num):
    total_ticket =0
    price_list.sort(reverse=True)

    while total_ticket < tickets_num:
        temp = price_list.pop(0)
        temp_new=temp//2
        price_list.append(temp_new)
        price_list.sort(reverse=True)
        total_ticket+=1
    return price_list

res = discount(price_list,M)
print(sum(res))

Submission status: Time Limit Exceeded

Solution code:
import sys
import bisect
sys.setrecursionlimit(10 ** 9)
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

_, M = lr()
A = lr()

A.sort()
for m in range(M):
    a = A[-1] // 2
    i = bisect.bisect_left(A, a)
    A.insert(i, a)
    A = A[:-1]
print(sum(A))

Submission status: Time Limit Exceeded

Solution code:
import numpy

def solution():
    n, m = map(int, input().split())
    a = [int(aa) for aa in input().split()]
    a.sort(reverse=True)
    for i in range(m):
        a[0] = a[0] // 2
        a = numpy.sort(a)[::-1]
    print(sum(a))

solution()

Submission status: Time Limit Exceeded

Solution code:
def solution():
    n, m = map(int, input().split())
    a = [int(aa) for aa in input().split()]
    a.sort(reverse=True)
    for i in range(m):
        a[0] = a[0] // 2
        a.sort(reverse=True)
    print(sum(a))

solution()

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
a_l = list(map(int, input().split()))
a_l.sort(reverse=True)

m_count = 0

while True:
    a_l[0] //= 2
    m_count += 1
    max_price = a_l[0]
    for j in range(1,n):
        if a_l[j] >= max_price:
            a_l[j] //2
            m_count += 1
            if m_count == m:
                break
        else:
            break
    a_l.sort(reverse=True)

ans = 0
for i in range(n):
    ans += a_l[i]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
a_l = list(map(int, input().split()))
a_l.sort(reverse=True)

for i in range(m):
    a_l[0] //= 2
    max_price = a_l[0]
    for j in range(1,n):
        if a_l[j] >= max_price:
            a_l[j] //2
        else:
            break
    a_l.sort(reverse=True)

ans = 0
for i in range(n):
    ans += a_l[i]
print(ans)

Submission status: Time Limit Exceeded

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

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

t.sort(reverse=True)

memo = []

for i in range(m):
    if len(memo) == 0:
        x=t.pop(0)
    elif len(t) == 0:
        x=memo.pop(0)
    elif t[0] >= memo[0]:
        x=t.pop(0)
    else:
        x=memo.pop(0)
    x = int(x/2)
    memo.append(x)
    #print(t)
print(sum(t)+sum(memo))

Submission status: Time Limit Exceeded

Solution code:
from bisect import insort

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

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

t.sort()

for i in range(m):
    x=t.pop(-1)
    x = int(x/2)
    insort(t, x)
    #print(t)
print(sum(t))

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
a_l = list(map(int, input().split()))
a_l.sort(reverse=True)

total = 0
for i in range(n):
    total += a_l[i]

for i in range(m):    
    total -= (a_l[0]+1)//2
    a_l[0] //= 2
    for j in range(n-1):
        if a_l[j] >= a_l[j+1]:
            break
        else:
            a_l[j], a_l[j+1] = a_l[j+1], a_l[j]

print(total)

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
a_l = list(map(int, input().split()))

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

for i in range(m):
    a_l.sort(reverse=True)
    sum -= (a_l[0]+1)//2
    a_l[0] //= 2

print(sum)

Submission status: Time Limit Exceeded

Solution code:
from bisect import insort_left

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

a_list = [int(x) for x in input().split()]
a_list.sort()

for _ in range(m):
    a_list[-1] //= 2
    insort_left(a_list, a_list.pop())
print(sum(a_list))

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
aa = list(map(int, input().split()))
import numpy as np

for i in range(m):
    ag = np.argmax(aa)
    aa[ag] = aa[ag] // 2
print(sum(aa))

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
As = list(map(lambda x: int(x), input().split()))


for _ in range(m):
  maxa=-1
  for i,a in enumerate(As):
    if maxa<a:
      maxa=a
      maxi=i
  As.pop(maxi)
  As.append(int(maxa/2))
  #print(As)
print(sum(As))

Submission status: Time Limit Exceeded

Solution code:
# https://atcoder.jp/contests/abc141/tasks/abc141_d
from copy import deepcopy
from heapq import heappop, heappush, heapify
n, m = map(int, input().split())

nums = [-int(i) for i in input().split()]
heapify(nums)
def check(nums, money, m):
    while m:
        m -= 1
        item = -1 * heappop(nums)
        item //= 2
        nums.append(-1 * item)
    pay = 0
    for num in nums:
        pay += -1 * num
        if pay > money:
            return False
    return True
l = 0
r = -1 * sum(nums)
ans = r
while l <= r:
    items = deepcopy(nums)
    mid = (l + r) // 2
    if check(items, mid, m):
        ans = min(ans, mid)
        r = mid - 1
    else:
        l = mid + 1
print(ans)

Submission status: Time Limit Exceeded

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

#n 買う商品数
#m 割引券の数
#a 値段

a.sort()
for i in range(m):
    tmp = a.pop(-1) //2
    a.append(tmp)
    a.sort()
print(sum(a))

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int,input().split())
a = list(map(int,input().split()))
a.sort(reverse=True)
def move(a):
    for i in range(len(a)-1):
        if a[i] < a[i+1]:
            a[i],a[i+1] = a[i+1],a[i]
        else:
            break
    return a
for i in range(m):
    a[0] //= 2
    a = move(a)
ans = 0
for x in a:
    ans += x
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import bisect
import copy

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

for _ in range(m):
    a[n-1] //= 2
    if a[n-1] < a[n-2]:
        b = a[:n-1]
        bisect.insort(b,a[n-1])
        a = copy.deepcopy(b)
    
print(sum(a))

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int,input().split())
a = list(map(int,input().split()))
a.sort(reverse = True)

for _ in range(m):
    a[0] //= 2
    a.sort(reverse = True)
    
print(sum(a))

Submission status: Time Limit Exceeded

Solution code:
import math
N,M=map(int,input().split())
S=input().split()
Snum=[]
for i in range(0,N):
  Snum.append(int(S[i]))
Snum.sort()
Snum.reverse()
for i in range(0,M):
  j=0
  k=math.floor(Snum[0]/2)
  while k<Snum[j] and j<N-1:
    j=j+1
  for l in range(0,j-1):
    Snum[l]=Snum[l+1]
  Snum[j-1]=k
print(sum(Snum))

Submission status: Time Limit Exceeded

Solution code:
import math
N,M=map(int,input().split())
S=input().split()
Snum=[]
for i in range(0,N):
  Snum.append(int(S[i]))
for i in range(0,M):
  k=Snum.index(max(Snum))
  Snum[k]=math.floor(Snum[k]/2)
print(sum(Snum))

Submission status: Time Limit Exceeded

Solution code:
N,M = map(int, input().split())
A = list(map(int, input().split()))
A = sorted(A)
while M > 0:
    A[-1] = A[-1] // 2
    M -= 1
    A = sorted(A)
print(sum(A))

Submission status: Time Limit Exceeded

Solution code:
N,M = map(int, input().split())
A = list(map(int, input().split()))
A = sorted(A)
while M > 0:
    A[-1] /= 2
    M -= 1
    A = sorted(A)
ans = 0
for i in A:
    ans += int(i)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N,M = map(int, input().split())
A = list(map(int, input().split()))
A = sorted(A, reverse=True)
def wb(X,Y):
    return int(X/(2**Y))
while M > 0:
    A[0] /= 2
    M -= 1
    A = sorted(A, reverse=True)
ans = 0
for i in A:
    ans += int(i)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def main():
  import bisect
  n,m = map(int,input().split())
  a = sorted(list(map(int,input().split())))
  for _ in range(m):
    x= a.pop(-1)/2
    index = bisect.bisect_left(a, x) 
    a.insert(index, x)
  print(int(sum(i//1 for i in a)))
if __name__=='__main__':
  main()

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int, input().split())
a = list(map(int, input().split()))
sub = [0]
a.sort()
for i in range (m):
    if (len(a) != 0):
        if (a[-1] >= sub[-1]):
            x =a.pop()
            sub.insert(1,x//2)
        else:
            x =sub.pop()
            sub.insert(1,x//2)
    else:
        x =sub.pop()
        sub.insert(1,x//2)
print(sum(a)+sum(sub))

Submission status: Time Limit Exceeded

Solution code:
n,m=map(int,input().split())
a=sorted(list(map(int,input().split())))
for i in range(m):
  a[-1]=a[-1]//2
  a=sorted(a)
print(sum(a))

Submission status: Time Limit Exceeded

Solution code:
import bisect
n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
cnt = 0
while cnt < m:
    x = a.pop()
    x = x // 2
    cnt += 1
    if len(a) == 0 or x > a[-1]:
        a.append(x)
    else:
        bisect.insort_left(a, x)
print(sum(a))

Submission status: Time Limit Exceeded

Solution code:
#141d
from collections import deque
import bisect
import math

N,M = map(int, input().split()) #1≤N,M≤10^5
A_list = list(map(int, input().split()))

#→高額なものに割引券を使った方が良い
if len(A_list)>1:
    A_list.sort(reverse=False)
    highest = A_list.pop()
    next_highest = A_list[-1]

    while 1:
        #print(A_list,highest)
        
        #highest/(pow(2,X)) <= next_highest に持っていきたい
        #highest <= next_highest * pow(2,X)
        #highest/next_highest <= 2**X
        #log2(highest/next_highest) <= X
        use_tickets = math.ceil(math.log2(highest/next_highest))
        if use_tickets == 0:
            use_tickets = 1
        if use_tickets > M:
            use_tickets = M
        highest /= pow(2,use_tickets)
        M -= use_tickets
        
        #print(A_list,highest)
        
        if M!= 0:
            bisect.insort(A_list,highest)
            highest = A_list.pop()
            next_highest = A_list[-1]
        else:
            A_list.append(highest)
            break

    A_list = [int(A) for A in A_list]
    print(sum(A_list))
else:
    A_list[-1] = A_list[-1]//(pow(2,M))
    print(A_list[-1])

Submission status: Time Limit Exceeded

Solution code:
#141d
from collections import deque
import bisect

N,M = map(int, input().split()) #1≤N,M≤10^5
A_list = list(map(int, input().split()))

#→高額なものに割引券を使った方が良い
if len(A_list)>1:
    A_list.sort(reverse=False)
    highest = A_list.pop()
    next_highest = A_list[-1]

    while 1:
        #print(A_list,highest)
        if highest>=next_highest:
            if M > 0:
                highest /= 2
                M -= 1
            else:
                A_list.append(highest)
                break
        else:
            bisect.insort(A_list,highest)
            highest = A_list.pop()
            next_highest = A_list[-1]

    A_list = [int(A) for A in A_list]
    print(sum(A_list))
else:
    while 1:
        if M > 0:
            A_list[-1] /= 2
            M -= 1
        else:
            print(int(A_list[-1]))
            break

Submission status: Time Limit Exceeded

Solution code:
from math import floor
N,M = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
while M>0:
    A[-1] /= 2
    M-=1
    i = -1
    while i != -N and A[i]<A[i-1]:
        A[i],A[i-1] = A[i-1],A[i]
        i-=1
print(sum(map(floor, A)))

Submission status: Time Limit Exceeded

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

for x in range(0, M):
  index = A.index(max(A))
  A[index] = A[index] // 2

print(sum(A))

Submission status: Time Limit Exceeded

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

for x in range(0, M):
  A.sort()
  A[len(A)-1] = A[len(A)-1]//2

print(sum(A))

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
items = list(map(int, input().split()))
for i in range(m):
    max_val_i = items.index(max(items))
    items[max_val_i] /= 2
print(sum(list(map(int, items))))

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
A = list(map(int, input().split()))
#print([bin(val) for val in A])

A.sort()
#print(A)

def binsearch(threshold, lst):
    left, right = -1, len(lst)
    while right - left > 1:
        mid = (right + left) // 2
        if lst[mid] >= threshold:
            right = mid
        else:
            left = mid
    return right

if N > 1:
    cnt = 0
    while cnt < M:
        while A[-1] >= A[-2] and cnt < M:
            A[-1] //= 2
            cnt += 1
        indx = binsearch(A[-1], A)
        A.insert(indx, A.pop(-1))
        #print(cnt, A)
    print(sum(A))
else:
    print(A[0] // 2**M)

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
A = list(map(int, input().split()))
#print([bin(val) for val in A])

A.sort()
#print(A)

def binsearch(threshold, lst):
    left, right = -1, len(lst)
    while right - left > 1:
        mid = (right + left) // 2
        if lst[mid] >= threshold:
            right = mid
        else:
            left = mid
    return right
for i in range(M):
    temp = A.pop(-1) // 2
    indx = binsearch(temp, A)
    #print(indx)
    if indx == N:
        A.append(temp)
    else:
        A.insert(indx, temp)
    #print(A)
print(sum(A))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N, M = map(int, input().split())
As = list(map(int, input().split()))

mvals = list(np.array(As) * (-1))
import heapq
heapq.heapify(mvals)

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

res = (np.array(mvals) * (-1)).astype(int).sum()
print(res)

Submission status: Time Limit Exceeded

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

for _ in range(M):

    max_A = max(A)
    ind = A.index(max_A)
    A[ind] = max_A//2

print(sum(A))

Submission status: Time Limit Exceeded

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

for _ in range(M):
    A[0] = A[0]//2
    A.sort(reverse=True)

print(sum(A))

Submission status: Time Limit Exceeded

Solution code:
import sys
import numpy as np
import bisect

N, M = map(int, sys.stdin.readline().split())
A = np.array(list(map(int, sys.stdin.readline().split())))
A.sort()

max = A[N - 1]

count = 0

while count < M:
    c = bisect.bisect_left(A, int(max / 2))
    add = N - c
    if count + add > M:
        d = M - count
        A[-d:] = A[-d:] // 2
        break
    else:
        A[c:] = A[c:] // 2
        count += add
    
ans = int(sum(A))

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
import numpy as np

N, M = map(int, sys.stdin.readline().split())
A = np.array(list(map(int, sys.stdin.readline().split())))

for _ in range(M):
    a = np.max(A)
    n = A.argmax()
    A[n] = int(a / 2)
    
ans = sum(A)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
import numpy as np

N, M = map(int, sys.stdin.readline().split())
A = list(map(int, sys.stdin.readline().split()))

for _ in range(M):
    a = max(A)
    n = A.index(a)
    A[n] = int(a / 2)
    
ans = sum(A)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N,M = list(map(int,input().split()))
A = list(map(int,input().split()))
for i in range(M):
    A.sort()
    A[len(A)-1] = A[len(A)-1] // 2
print(sum(A))

Submission status: Time Limit Exceeded

Solution code:

#D
import bisect


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

a.sort()

for i in range(m):
    a[-1] //= 2
    tmp = a.pop(-1)
    k = bisect.bisect_left(a,tmp)
    a.insert(k,tmp)
        
    
print(sum(a))

Submission status: Time Limit Exceeded

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

a.sort(reverse=True)

while m>0:
    a[0] //= 2
    m -= 1
    a.sort(reverse=True)
    
print(sum(a))

Submission status: Time Limit Exceeded

Solution code:
import sys
stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

N,M=nl()
A=nl()

for i in range(M):
	A.sort()
	A[-1]=A[-1]//2

print(sum(A))

Submission status: Time Limit Exceeded

Solution code:
import sys
import collections
stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

N,M=nl()
A=nl()

for i in range(M):
    inds=A.index(max(A))
    A[inds]=A[inds]//2

print(sum(A))

Submission status: Time Limit Exceeded

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

for _ in range(m):
    x = A.pop()
    x //= 2
    bisect.insort_right(A, x)
print(sum(A))

Submission status: Time Limit Exceeded

Solution code:
import bisect
import sys
input = sys.stdin.readline

n, m = map(int, input().split())
A = list(map(int, input().split()))
A.sort()

for _ in range(m):
    max_price = A.pop(-1) // 2
    bisect.insort(A, max_price)

total = sum(A)
print(total)

Submission status: Time Limit Exceeded

Solution code:
import bisect
import sys
input = sys.stdin.readline

n, m = map(int, input().split())
A = list(map(int, input().split()))
A.sort()

for _ in range(m):
    max_price = A.pop(-1) // 2
    next_index = bisect.bisect(A, max_price)
    A.insert(next_index, max_price)

total = sum(A)
print(total)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline

n, m = map(int, input().split())
A = list(map(int, input().split()))
A.sort()

for _ in range(m):
    max_price = max(A)
    max_index = A.index(max_price)
    max_price //= 2
    A[max_index] = max_price

total = sum(A)
print(total)