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:
import numpy as np
import sys
input = sys.stdin.readline


N, M = map(int, input().split())
A = list(map(int, input().split()))+[0]

A.sort(reverse=True)
tmp = 0
for _ in range(M):
    A[0] >>= 1
    if A[0] < A[1]:
        tmp = A[0]
        for i in range(1, N+1):
            if tmp < A[i]:
                A[i-1] = A[i]
            else:
                A[i-1] = tmp
                break
print(sum(A))

Submission status: Time Limit Exceeded

Solution code:
import bisect

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

A.sort()
#print(A)
for i in range(M):
    if(A[len(A)-1]==0):
        continue
    score=A[len(A)-1]//2
    num = bisect.bisect_right(A,score)
    #print("score=" + str(score) +" num="+str(num))
    score=[score]
    #print(A[0:num])
    A=A[0:num] + score + A[num:-1]
    #print(A)

total=0
for i in A:
    total+=i

print(total)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

while M > 0:
    if A[0] == 0:
        break
    if len(A) < 2:
        t = M
    else:
        t = (A[0] // A[1])
    A[0] //= 2**t
    A.sort(reverse=True)
    M -= t
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()
   a.append(a.pop(n-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()
for i in range(M):
  A[-1] = A[-1]//2
  A.sort()
print(sum(A))

Submission status: Time Limit Exceeded

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

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

while M > 0:
    m_index = A.index(max(A))
    m = A.pop(m_index)
    for i in range(1, M+1):
        tmp = int(m/(2**i))
        if tmp < max(A):
            M -= i
            A.append(tmp)
            break
print(sum(A))

Submission status: Time Limit Exceeded

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

List.sort()
for i in range(m):
  new = max(List)
  List.remove(max(List))
  List.append((new/2)//1)

print(int(sum(List)))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:

NM = [int(i) for i in input().split(" ")]
N = int(NM[0])
M = int(NM[1])
As = [int(i) for i in input().split(" ")]
W = len(As) - 1
As.sort(reverse=True)
for i in range(M):
    As.sort()
    As[W] = As[W] // 2
print(sum(As))

Submission status: Time Limit Exceeded

Solution code:
nm = input()
a = input()

nm = nm.split()
n = int(nm[0])
m = int(nm[1])
a = [int(x) for x in a.split()]


for i in range(m):
    list_max = max(a)
    index = a.index(list_max)
    a[index] = a[index]//2

output = sum(a)
print(output)

Submission status: Time Limit Exceeded

Solution code:
import math
import bisect

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

for i in range(M):
    n = A.pop() / 2
    bisect.insort(A, n)

answer = 0
for j in range(N):
    answer += math.floor(A[j])

print(answer)

Submission status: Time Limit Exceeded

Solution code:
import math

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

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
prices = [int(p) for p in input().split()]
prices.sort()
for _ in range(m):
    prices[-1] //= 2
    prices.sort()
print(sum(prices))

Submission status: Time Limit Exceeded

Solution code:
import bisect
N,M=[int(i) for i in input().split()]
A = sorted([int(i) for i in input().split()])
for i in range(M):
  A2=A[N-1]//2
  A.pop(N-1)
  bisect.insort_left(A,A2)
print(sum(A))

Submission status: Time Limit Exceeded

Solution code:
import bisect

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

A = sorted(list(map(int, input().split())))
for _ in range(M):
    B = int(int(A.pop(len(A)-1))/2)
    bisect.insort(A, B)

result = 0
for i in A:
    result += int(i)

print(result)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

a_dic = {}
for i, a in enumerate(A):
    a_dic[i] = a

for m in range(M):
    max_a = max(a_dic, key=a_dic.get)
    a_dic[max_a] = a_dic[max_a] // 2

ans = sum(a_dic.values())
if ans < 0:
    ans = 0
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
[N, M] = list(map(int,input().split()))
A = list(map(int,input().split()))
P = [0]*N
for i in range(N):
    P[i] = A[i]
P.sort(reverse = True)
for i in range(N):
    A[i] = math.log2(A[i])
A.sort(reverse = True)
M_temp_old = [0]*N
M_temp_new = [0]*N
for j in range(N):
    for i in range(j):
        M_temp_new[i] += math.ceil(A[i] - A[j])
    if sum(M_temp_new) > M:
        break
    else:
        M_temp_old = M_temp_new
        M_temp_new = [0]*N
while M - sum(M_temp_old) >= N:
    for i in range(N):
        M_temp_old[i] += 1
for i in range(N):
    P[i] = P[i]//(2**M_temp_old[i])
P.sort(reverse = True)
for i in range(M - sum(M_temp_old)):
    P[i] = P[i]//2
print(sum(P))

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[a.index(max(a))]/=2
print(sum(list(map(int,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:
N,M=map(int,input().split())
A=list(map(int,input().split()))
A.sort(reverse=True)
j=0
for i in range(M):
    A[A.index(max(A[:j+1]))]=A[A.index(max(A[:j+1]))]//2
    j=j+1
    if j==100:
        A.sort(reverse=True)    
        j=0
print(sum(A))

Submission status: Time Limit Exceeded

Solution code:
import sys

input = sys.stdin.readline


def main():
    n, m = map(int, input().split())
    a = list(map(int, input().split()))
    a=sorted(a,reverse=True)
    for i in range(m):
        if n>=2 and a[1]!=0:
            x=a[0]//a[1]
            if x<=m:
                a[0]//=2**x
                m-=x
            elif x>m and m>0:
                a[0]//=2**m
                m=0
        else:
            a[0]//=2**m
            m=0
        if m==0:
            break
        a = sorted(a, reverse=True)

    print(sum(a))


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys
from bisect import bisect_left,bisect

if sys.platform =='ios':
    sys.stdin=open('input_file.txt')
    
n,m=map(int,input().split())



A=list(map(int,input().split()))
A=sorted(A)

if len(A)>10**5:
	Al=A[-10**5:]
	Af=A[:-10**5]
	for i in range(m):
		Al.insert(bisect_left(Al,max(Al)//2),max(Al)//2)
		del Al[n]
	print(sum(Al)+sum(Af))
	
else:
	for i in range(m):
		A.insert(bisect_left(A,max(A)//2),max(A)//2)
		del A[n]
	
	print(sum(A))

Submission status: Time Limit Exceeded

Solution code:
NM = input().split(" ")
A_LIST = input().split(" ")
A = []
for i in A_LIST:
    A.append(int(i))

N = int(NM[0])
M = int(NM[1])

A.sort()
for i in range(0, M):
    if A[N-1] >= A[N-2]:
        m = A[N-1]
        m = m // 2
        A[N-1] = m
    elif A[N-2] >= A[N-3]:
        m = A[N-2]
        m = m // 2
        A[N-2] = m
        A.sort()
S = 0
for i in A:
    S += i
print(S)

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split()) 
A = [int(a) for a in input().split()]
for i in range(m): 
    A[A.index(max(A))] /= 2
A = [int(a) for a in 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(reverse=True)
tmp = []
tmp.append(A[0])
output = sum(A)

j = 1
for i in range(M):
    m = max(tmp)
    if j < N:
        if m < A[j]:
            tmp.append(A[j] // 2)
            output = output - A[j] + A[j] // 2
            j += 1
        else:
            output = output - m + m // 2
            tmp.remove(m)
            tmp.append(m // 2)
    else:
        output = output - m + m // 2
        tmp.remove(m)
        tmp.append(m // 2)

print(output)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n, m = map(int, input().split())
a = [int(i) for i in input().split(" ")]
b = np.array(a, dtype="object")
for i in range(m):
    b[b.argmax()] /= 2
print(int(np.sum(b//1)))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n, m = map(int, input().split())
L = np.array([int(i) for i in input().split()], dtype=int)

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

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()))
A = np.array(A)

for i in range(M):
    j = A.argmax()
    A[j]  =  math.floor(A[j] / 2)

print(A.sum())

Submission status: Time Limit Exceeded

Solution code:
n,m=map(int,input().split())
lista = [int(i) for i in input().split()]
lista.sort()

dic = {}
for i in range(31):
    dic[i] = []

i2 = 0

for i in range(len(lista)):
    while(lista[i]>=2**(i2+1)):
        i2+=1
    dic[i2].append(lista[i])
    
#print(dic)

end = False
for t in range(i2,0,-1):
    list_d = dic[t]
    list_d.sort()
    loop = len(list_d)
    if loop<m:
        for i in range(loop):
            list_d[i] = list_d[i]/2
        dic[t-1] = dic[t-1]+list_d
        list_d = []
        m = m-loop
    else:
        for i in range(loop):
            tmp = list_d[-1]
            dic[t-1].append(tmp/2)
            list_d =  list_d[:-1]
            m = m-1
            if m==0:
                end = True
                dic[t] = list_d
                break

    dic[t] = list_d
    if end == True:
        break
        
        
"""print(dic)
print(m)"""
ans = 0
if m > 0:
    ans = n-m
    if ans >= 0:
        print(n-m)
    else:
        print(0)
else:
    for i in range(t+1):
        list_d = dic[i]
        #print(i,list_d)
        for l in range(len(list_d)):
            tmp = list_d[l]
            ans+=int(tmp)
    print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

for i in range (m):
    cost=sorted(cost)
    cost[-1]=cost[-1]//2

print(sum(cost))

Submission status: Time Limit Exceeded

Solution code:
import math

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

for i in range(n[1]):
    a.sort(reverse=True)
    a[0] = math.floor(a[0] / 2)

print(sum(a))

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
import math
N,M=list(map(int,input().split()))
A=list(map(int,input().split()))
#rec(N-1,M)
res=dict(Counter(A))
while M>0:
    #ex=max(list(map(float,res.keys())))
    ex=max(res.keys())
    n=res[ex]
    val=ex//2
    if n<=M:
        M-=n
        del res[ex]
        
        if val in res.keys():
            res[val]+=n
        else:
            res[val]=n
            
        
    else:
        n=M
        res[ex]-=n
        if val in res.keys():
            res[val]+=n
        else:
            res[val]=n
        M=0
    
ans=0
for i in res.keys():
    ans+=i*res[i]
print(int(ans))

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import math
def main():
    N,M = map(int,input().split())
    A = list(map(int,input().split()))
    for _ in range(M):
        MAX = max(A)
        tmpi = A.index(MAX)
        A[tmpi] = math.floor(A[tmpi]-(MAX/2))
    print(sum(A))
if __name__ == '__main__':
    main()

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[A.index(max(A))] //= 2
print(sum(A))

Submission status: Time Limit Exceeded

Solution code:
n,m=map(int,input().split())
a=[int(i) for i in input().split()]
while m>0:
    a.sort()
    b=a.pop()
    a.append(b//2)
    m-=1
print(sum(a))

Submission status: Time Limit Exceeded

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

while remain > 0:
  i = A.index(max(A))
  A[i] = A[i]//2
  remain -= 1
print(sum(A))

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin

s=stdin.readline().rstrip().split()
N=int(s[0])
M=int(s[1])
count=0

a=stdin.readline().rstrip().split()
for i in range(N):
  a[i]=int(a[i])

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

print(sum(a))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

B = A.copy()
discount_cnt = np.zeros(N)

num = 0

while num < M:
    tmp = B / 2
    tmp_idx = np.argmax(tmp)
    discount_cnt[tmp_idx] += 1
    B[tmp_idx] = tmp[tmp_idx]
    num += 1

tmp_arr = np.array([2 ** i for i in discount_cnt])
print(int(np.sum(np.floor(A / tmp_arr))))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N,M = map(int, input().split())
ls = list(map(int, input().split()))
 
def half(l):
  a=l.index(max(l))
  l[a]=l[a]//2
  return(l)
for i in range(M):
  half(ls)
print(sum(ls))

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
import math
import numpy as np

def where(x):
  return np.array(np.where(x))

n, m = map(int, input().split())
a = np.array(list(map(int, input().split())))
a = np.sort(a)
b = np.log2(a)
b = np.array(list(map(int, b)))
mx = np.max(b)

while m != 0:
  mask = where(b == mx).flatten()
  if len(mask) == 0:
      mx -= 1
      continue
  if len(mask) <= m:
    b[mask] = b[mask] - 1
    a[mask] = a[mask] / 2
    m -= len(mask)
    mx -= 1
  else:
    while m != 0:
      a = np.sort(a)
      a[n-1] /= 2
      m -= 1

a = map(int, a)
print(sum(a))

Submission status: Time Limit Exceeded

Solution code:
N,M = map(int, input().split())
A = list(map(int, input().split()))
value = sum(A)
A.append(-1)

cards = M

for i in range(M):
    A = sorted(A,reverse=True)
    p = 0
    while A[p] == max(A) > 0 and cards >= 1:
        A[p] //= 2
        p += 1
        cards -= 1
    if cards == 0 or max(A) == 0:
        break

A.pop()
print(sum(A))

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect

#n:shinamono no kazu
#m:waribiki maisuu

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

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

indexMax=len(a)-1

for _ in range(m):
  maxA=a[indexMax]
  a.pop(indexMax)
  a.insert(bisect(a, maxA/2.0), maxA/2.0)

#print(a)
result=0
for item in a:
  result+=item//1
  
print(int(result))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

import sys

debug = False

def log(text):
    if debug:
        print(text)

def parse_input(lines_as_string = None):

    global debug
    lines = []
    if lines_as_string is None:
        debug = False
        lines.append(input())
        lines.append(input())
    else:
        debug = True
        lines = [e for e in lines_as_string.split("\n")][1:-1]

    tokens = lines[0].split(" ")
    n = int(tokens[0])
    m = int(tokens[1])

    a = [int(e) for e in lines[1].split(" ")]    

    return (n, m, a)


def solve(n, m, a):

    for i in range(m):

        max_tmp = -1
        max_index_tmp = -1
        for j in range(n):
           if a[j] > max_tmp:
               max_tmp = a[j]
               max_index_tmp = j
        
        a[max_index_tmp] = a[max_index_tmp] // 2

    return sum(a)


def main():
    # 出力
    result = solve(*parse_input())
    if isinstance(result, list):
        for r in result:
            print("%s" % r)
    else:
        print("%s" % result)


if __name__ == '__main__':

    main()

Submission status: Time Limit Exceeded

Solution code:
N,M = map(int, input().split())
A = sorted(map(int, input().split()))[::-1]
 
total = 0
for i in range(M):
    A[0] = A[0] // 2
    for j in range(N-1-i):
        if A[j] < A[j+1]:
            tmp = A[j]
            A[j] = A[j+1]
            A[j+1] = tmp
        else:
            break
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):
    index = As.index(max(As))
    As[index] = As[index] // 2

print(sum(As))

Submission status: Time Limit Exceeded

Solution code:
import numpy
def main():
  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))
main()

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import math

n,m = map(int,input().split())
all_price = list(map(int, input().split())) 
all_price = np.array(all_price)
for i in range(m):
    t = np.argmax(all_price)
    all_price[t] = (all_price[t]/2)

print(math.floor(np.sum(all_price)))

Submission status: Time Limit Exceeded

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

A.sort(reverse=True)
if len(A) == 1:
    A[0] = A[0] // (2**M)
else:
    while M > 0:
        #割引券なくなるまで
        # index:0 と index:1 を比較して一気に何枚が使う
        m = A[0] // A[1] // 2 + 1
        A[0] //= (2**m)
        M -= m
        A.sort(reverse=True)
print(sum(A))

Submission status: Time Limit Exceeded

Solution code:
N, M = [int(n) for n in input().split()]
A = sorted([int(n) for n in input().split()], reverse=True)
for _ in range(M):
    A[0] //= 2
    if len(A)!=1:
        if A[0] < A[1]:
            A = sorted(A, 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()
for i in range(m):
        a[-1] //= 2
        a.sort()
print(sum(a))

Submission status: Time Limit Exceeded

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

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

for i in range(m):
  prices.sort()
  prices[n-1] = prices[n-1] // 2
  
print(sum(prices))

Submission status: Time Limit Exceeded

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

l.sort(reverse=True)
for i in range(m):
    l[0]=l[0]//2
    l.sort(reverse=True)
total=0
for j in range(len(l)):
    total+=l[j]

print(total)

Submission status: Time Limit Exceeded

Solution code:
ss = input().split()
N = int(ss[0])
M = int(ss[1])

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

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

Submission status: Time Limit Exceeded

Solution code:
n ,m = map(int,input().split())
arr =list(map(int,input().split()))
for _ in range(m):
  j = max(arr)//2
  arr.remove(max(arr))
  arr.append(j)
print(sum(arr))

Submission status: Time Limit Exceeded

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


def main():
    n, m = map(int, input().split())

    if n == 1:
        a = int(input())
        for i in range(m):
            a //= 2
        print(a)
        exit()

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

    for i in range(m):
        mx = max(a)
        a[a.index(mx)] //= 2
    print(sum(a))


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
N,M = map(int, input().split())
A = list(map(int, input().split()))
 
def second_large(x):
    y = x.copy()
    y.remove(max(y))
    return max(y)
 
if N>=2:
  while M>=1:
    fm_n = max(A)
    sm_n = second_large(A)
    div_m = fm_n/sm_n
    i=1
    while 2**(i+1)<=div_m:
      i+=1
 
    if M>=i:
      A[A.index(max(A))]=fm_n//(2**i)
      M -= i
    else:
      A[A.index(max(A))]=fm_n//(2**M)
      M = 0
 
  print(sum(A))
else:
    i=1
    while 2**(i+1)<=A[0]:
      i+=1
    if M>=i:
      print(0)
    else:
      print(A[0]//2**M)

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10000)


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


def dfs(a, m):
    if max(a) == 0:
        return 0
    if m == 0:
        return sum(a)
    a[a.index(max(a))] //= 2
    return dfs(a, m-1)


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

    #print(dfs(A, M))
    for i in range(M):
        A[A.index(max(A))] //= 2
        if max(A) == 0:
            print("0")
            exit()
    print(sum(A))


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

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

print(sum(A))

Submission status: Time Limit Exceeded

Solution code:
import math

def main():
    #tmp = input()
    tmp = input()
    tmp_s = [int(x.strip()) for x in tmp.split(' ')]
    N = tmp_s[0] #num of stuff
    M = tmp_s[1] #num of discount
    A_tmp = input()
    A = [int(x.strip()) for x in A_tmp.split(' ')]
    for i in range(M):
        flag = A.index(max(A))
        A[flag] = math.floor(A[flag]/2)

    print(sum(A))

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())  # 品物の数、割引券の枚数
A = list(map(int, input().split()))  # 品物の値段
for _ in range(M):
    tmp = A.index(max(A))
    A[tmp] = A[tmp] // 2
print(str(sum(A)))

Submission status: Time Limit Exceeded

Solution code:
#import numpy as np
N,M=input().split(" ")
N=int(N)
M=int(M)
Alist=input().split(" ")
Alist = [float(A) for A in Alist]


for m in range(M):
    i=Alist.index(max(Alist))
    Alist[i]=Alist[i]/2
    # print(Alist)


Alist_i = [int(A) for A in Alist]

print(sum(Alist_i))

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()
    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 = sorted(a,reverse=True)
for m in range(M):
  if len(a)>1:
    max_=max(a[:2])
    a.remove(max_)
    flag=1
    for n in range(N-1):
      if max_//2<a[n]:
        continue
      else:
        a.insert(n,max_//2)
        flag=0
        break
    if flag:
      a.append(max_//2)
  else:
    a[0]=a[0]//2
print(sum(a))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
one = input()
two = input()

# one = '3 3'
# two = '2 13 8 12'

N, M = map(int, one.split())
Ar = list(map(int, two.split()))
# Ar = sorted(Ar , reverse=True)
Ar.sort(reverse=True)

for i in range(M):
    Ar[0] = Ar[0] / 2
    Ar.sort(reverse=True)
    # Ar = sorted(Ar , reverse=True)
    # for i in range(len(Ar)):
    #     if Ar[i] < Ar[i+1]:
    #         temp = Ar[i]
    #         Ar[i] = Ar[i+1]
    #         Ar[i+1] = temp
    #     else:
    #         break

Ar = map(int, Ar)
print(sum(Ar))

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
import bisect

N, M = map(int, input().split(" "))
As = [0]+list(map(int, input().split(" ")))
As = sorted(As)
cnt = 0
cnt2 = 1
for _ in range(M):
  i = As[-1-cnt]  
  i = i//(2**cnt2)
  if i < As[-1-cnt-1]:
    cnt += 1
    cnt2 = 1
    bisect.insort_left(As,i)
  else:
    cnt2 += 1

print(sum(As[:-cnt]))

Submission status: Time Limit Exceeded

Solution code:
import bisect

n, m = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
a = a[-100001:]


for i in range(m):
    x = a[-1]
    a.pop()
    x //= 2
    insert_index = bisect.bisect_left(a, x)
    a.insert(insert_index, x)
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[N-1]=A[N-1]//2
    if A[N-2]>A[N-1]:
        A.sort()
    if A[N-1]==0:
        break
print(sum(A))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np


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

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

nparr = np.array(a)

tmp = 0
data = 0

for i in range(m):

        tmp = np.argmax(a)

        data = np.floor(a[tmp]/2)

        a = np.delete(a, tmp)

        a = np.append(a, data)


print(int(np.sum(a)))

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[A.index(max(A))] = max(A) // 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()))

    sort_A = sorted(A, reverse=True)


    for _ in range(M):
        sort_A[sort_A.index(max(sort_A))] = max(sort_A) // 2

    print(sum(sort_A))

main()

Submission status: Time Limit Exceeded

Solution code:

import sys
input = sys.stdin.readline
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
##############################

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

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

A.sort(reverse=True)
count = 0

A[0] //= 2
M -= 1
while M > 0:
    max_i = 0
    max_p = A[0]

    for i in range(1, N):
        if max_p < A[i]:
            max_p = A[i]
            max_i = i

        if A[i-1] < A[i]:
            break

    A[max_i] //= 2
    M -= 1

print(sum(A))

Submission status: Time Limit Exceeded

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

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

print(sum(A))

Submission status: Time Limit Exceeded

Solution code:
nm = input()
a = input()

nm = nm.split()
n = int(nm[0])
m = int(nm[1])
a = a.split()
a = [int(x) for x in a]


for i in range(m):
    list_max = max(a)
    index = a.index(list_max)
    a[index] = a[index]//2

output = sum(a)
print(output)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
#入力
N,M=map(int,input().split())
a=list(map(int,input().split()))

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

print("{}".format(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)


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

for _ in range(M):
    A[0] = A[0]//2
    #print(A,_)

    if A[0] < A[1]:
        popA = A.pop(0)

        index = 0
        #print(A)
        #print(popA,A[index])
        while popA <= A[index] or index == N - 1:
            index = index + 1
            if(index == N-1):break
        A.insert(index,popA)
        #print(A,index)

#print(A)
print(sum(A))

Submission status: Time Limit Exceeded

Solution code:
x = map(int,raw_input().split())
n=x[0]
m=x[1]
a = map(int,raw_input().split())
a=list(map(float, a))                                                           

for i in range(m):                                                         
    a[a.index(max(a))]=max(a)/2

a=list(map(int, a))

print(sum(a))

Submission status: Time Limit Exceeded

Solution code:
N, M = [int(x) for x in input().split()]
all_price = [int(x) for x in input().split()]
all_price.sort(reverse=True)

for num in range(M):
    max_index = all_price.index(max(all_price))
    all_price[max_index] = all_price[max_index] >> 1

print(sum(all_price))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
 
n, m = map(int, input().split())
a = np.array(list(map(int, input().split())))
cnt = -1

for i in range(m):
  idx = a.argmax()
  if a[idx] <= 2:
    cnt = i
    break
  a[idx] //= 2

if cnt < 0:
  cnt = m
print(max(np.sum(a) - (m - cnt), 0))

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
import bisect
import math
N, M = map(int, input().split())

A = sorted([-int(_) for _ in input().split()])
deq = deque(A)

for m in range(M):
    div = deq.popleft()
    div = math.ceil(div / 2)
    tmp_lis = list(deq)
    #print(tmp_lis)
    bisect.insort(tmp_lis, div)
    deq = deque(tmp_lis)
print(-sum(deq))

Submission status: Time Limit Exceeded

Solution code:
import bisect
N,M = map(int,input().split())
A = (list(map(int,input().split())))
A.sort()
for i in range(M):
  mx = A.pop()
  insert_index = bisect.bisect_left(A,mx//2)
  A.insert(insert_index,mx//2)
print(sum(A))