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(int, input().split()))

l = len(A)
A.sort(reverse=True)

if N>=2:
  while M>=1:
    div = A[0]//2
    
    for i in range(l):
      if A[i]>=div:
        if M>=1:
          A[i] = A[i]//2
        else:
          break
      else:
        break
 
  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:
N,M=map(int,input().split())
*A,=map(int,input().split())
d={}
for a in A:
    k=a
    while k>=1:
        d[k-k//2]=d.get(k-k//2,0)+1
        k=k//2
s=0
i=0
for k in sorted(list(d.keys()), key=lambda x:-x):
    if i+d[k]<=M:
        i+=d[k]
        s+=k*d[k]
    else:
        s+=k*(M-i)
        break
print(sum(A)-s)

Submission status: Time Limit Exceeded

Solution code:
import math
 
N,M = map(int, input().split())
L = list(map(int, input().split()))
 
L = sorted(L,reverse=True)
 
 
for i in range(0,M):
	L[0] = int(math.floor(L[0] / 2))
	L = sorted(L,reverse=True)
	
print(sum(L))

Submission status: Time Limit Exceeded

Solution code:
import math

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

L = sorted(L,reverse=True)


while M > 0:
	L[0] = int(math.floor(L[0] / 2))
	L = sorted(L,reverse=True)
	
	M -= 1
	
print(sum(L))

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:
n,m = map(int,input().split())
arr = list(map(int,input().split()))

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

Submission status: Time Limit Exceeded

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

list1.sort()
j = 0
for i in range(m):
    a = list1.pop() // 2
    for j in range(n-1)[::-1]:
        if a > list1[j]:
            break
    list1.insert(j+1, a)

print(sum(list1))

Submission status: Time Limit Exceeded

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

def main():
    n, m = map(int, input().split())
    # a = [int(i) for i in input().split()]
    # a.sort()
    a = []
    for i in map(int, input().split()):
        insort_left(a, i)
    for _ in range(m):
        b = a.pop()//2
        insort_left(a, b)
    print(sum(a))


main()

Submission status: Time Limit Exceeded

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

a.sort(reverse=True)

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

count = 0
for i in range(n):
    count += int(a[i])
print(count)

Submission status: Time Limit Exceeded

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

def main():
    n, m = map(int, input().split())
    a = [int(i) for i in input().split()]
    a.sort()
    for _ in range(m):
        b = a.pop()//2
        insort_left(a, b)
    print(sum(a))


main()

Submission status: Time Limit Exceeded

Solution code:
n, d = map(int, input().split())
a = list(map(int, input().split()))
c = 0
while c != d:
    c += 1
    t = a.index(max(a))
    a[t] = max(a)//2
    if max(a) == 0:
        print(sum(a))
        quit()
else:
    print(sum(a))

Submission status: Time Limit Exceeded

Solution code:
import math

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

L = sorted(L,reverse=True)


for i in range(0,M):
	L[0] = int(math.floor(L[0] / 2))
	L = sorted(L,reverse=True)
	
print(sum(L))

Submission status: Time Limit Exceeded

Solution code:
import math

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

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

print(sum(prices))

Submission status: Time Limit Exceeded

Solution code:
# Y 割引券の枚数
# 割引 = x / 2 ** Y
import math

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


for i in range(M):
    prices[prices.index(max(prices))] = math.floor(prices[prices.index(max(prices))] / 2)
    # print(prices[i])
    # prices[i] / 2 ** Y

print(sum(prices))

Submission status: Time Limit Exceeded

Solution code:
import math
import numpy as np
N,M=map(int,input().split())
A=np.array(list(map(int,input().split())))
for i in range(M):
    A[A.argmax()]/=2
ans=0
for a in A:
    ans+=math.floor(a)
print(ans)

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

Submission status: Time Limit Exceeded

Solution code:
import bisect
 
N, M = map(int, input().split(" "))
As = [0]+list(map(int, input().split(" ")))
As.sort()
cnt = 0
cnt2 = 1
for j in range(M):
  i = As[-1-cnt]  
  i = i//(2**cnt2)
  if j == M-1 or 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 heapq as hq

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

arr = [-i for i in list(map(int,input().split()))]
hq.heapify(arr)

for i in range(m):
    arr[0] = -1*(-1*arr[0]//2)
    hq.heapify(arr)

    
print(-1*sum(arr))

Submission status: Time Limit Exceeded

Solution code:
import bisect
 
N, M = map(int, input().split(" "))
As = [0]+list(map(int, input().split(" ")))
As.sort()
cnt = 0
cnt2 = 1
for j in range(M):
  i = As[-1-cnt]  
  i = i>>cnt2
  if j == M-1 or 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 sys
def p(*_a):
  _s=" ".join(map(str,_a))
  #print(_s)
  sys.stderr.write(_s+"\n")
#-------------------------------------------------------------------
from heapq import heappush
from heapq import heappop
from heapq import heappushpop
from heapq import nlargest
from heapq import nsmallest
#-------------------------------------------------------------------

N, M = map(int, input().split())		# 5 7 2
A = list( map(int, input().split()) )

p("A ",A)

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

H=[]
for a in A:
	heappush(H,a*(-1))

p("H ",H)

while M>0:
	h = heappop(H)
	if int(h)==1: break

	h/=2
	M-=1
	
	heappush(H,h)
	
	p("h,H ",h,H)

ans=0
for h in H:
	ans += int(h*(-1))

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import bisect
import math
import sys

input = sys.stdin.readline

n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
for i in range(m):
    # print(a)
    # print(math.floor(a[-1] / 2))
    b = bisect.bisect_left(a, math.floor(a[-1] / 2))
    a.insert(b, math.floor(a[-1] / 2))
    a.pop(-1)

    if len(a) == 1:
        print(math.floor(a[0] / 2**(m - i - 1)))
        exit()
print(sum(a))

Submission status: Time Limit Exceeded

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

A = list(map(lambda x: int(x), input().split(' ')))
A.sort(reverse=True)

for _ in range(M):
    A[0] = A[0] // 2
    for i in range(N-1):
        if A[i] < A[i+1]:
            A[i+1], A[i] = A[i:i+2]
        else:
            break

print('{}'.format(sum(A)))

Submission status: Time Limit Exceeded

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

def heapsort(iterable):
    h = []
    for value in iterable:
        heapq.heappush(h, value)
    return [heapq.heappop(h) for i in range(len(h))]

N,M=map(int,input().split())
A=heapsort(list(map(int, input().split())))
for i in range(M):
  A[N-1]=A[N-1]/2
  for j in range(N-1,0,-1):
    if A[j-1]>A[j]:
      a=A[j-1]
      A[j-1]=A[j]
      A[j]=a
    else:
      break
  #print(A)
ans=0
for i in range(N):
  ans+=math.floor(A[i])
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N, M, *A, = map(int, open(0).read().split())
A.sort(reverse=True)
Amae = A[:M]
Aushiro = A[M:]
for _ in range(M):
    Amae[0] = Amae[0] // 2
    Amae.sort(reverse=True)
print(sum(Amae) + sum(Aushiro))

Submission status: Time Limit Exceeded

Solution code:
import sys
import math
input= sys.stdin.readline
N, M = map(int,input().split())
 
A= list(map(int,input().split()))
 
A.sort(reverse=True)
cnt = 1
A[0]=A[0]//2
 
if N==1:
    while A[0]>0 and cnt<M:
        cnt+=1
        A[0]=A[0]//2
else:
    while cnt<M:
        c=min(M-cnt,int(math.log2(A[0]/A[1])+1))
        cnt+=c
        A[0]=A[0]//(2**c)
          
        b=A[0]
        A.sort(reverse=True)
    
print(sum(A))

Submission status: Time Limit Exceeded

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

A = list(map(lambda x: int(x), input().split(' ')))
A.sort(reverse=True)

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

print('{}'.format(sum(A)))

Submission status: Time Limit Exceeded

Solution code:
import bisect
N,M = map(int,input().split())
As = [int(i) for i in input().split()]
 
As.sort()
 
for _ in range(M):
    takai = As.pop()
    takai//=2
    bisect.insort_right(As,takai)
print(sum(As))

Submission status: Time Limit Exceeded

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

N,M = map(int,input().split())
A_list = sorted(list(map(int,input().split())),reverse=True)


for i in range (M):
    A_list[0] = A_list[0]//2
    A_list = sorted(A_list,reverse=True)

print(sum(A_list))

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
a = list([int(x) for x in 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:
import bisect
 
N, M = map(int, input().split(" "))
As = [0]+list(map(int, input().split(" ")))
As.sort()
cnt = 0
cnt2 = 1
for _ in range(M):
  i = As[-1-cnt]  
  i = i>>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:
sin = input()
n, m = map(int, sin.split())
sin = input()
an = list(map(int, sin.split()))
an.sort()
an.reverse()

#print(an)
for i in range(m):
    an[0] = int(an[0] / 2)
    ire = False
    for ii in range(1, n-1):
        #print(ii)
        if an[0] < an[ii]:
            es = ii
            ire = True
            continue
        else:
            break

    if ire:
        iii = an[0]
        del an[0]
        an.insert(es, iii)

    #print(an)

print(sum(an))

Submission status: Time Limit Exceeded

Solution code:
import heapq

n, m = map(int, input().split())
prices = [int(p) for p in input().split()]
heapq._heapify_max(prices)
for _ in range(m):
    prices[0] //= 2
    heapq._heapify_max(prices)
print(sum(prices))

Submission status: Time Limit Exceeded

Solution code:
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>>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
import math

n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
for i in range(m):
    # print(a)
    # print(math.floor(a[-1] / 2))
    b = bisect.bisect_left(a, math.floor(a[-1] / 2))
    a.insert(b, math.floor(a[-1] / 2))
    a.pop(-1)

    if len(a) == 1:
        print(math.floor(a[0] / 2**(m - i - 1)))
        exit()
print(sum(a))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import math

n, m = map(int, input().split(' '))
prices = np.array(list(map(int, input().split(' '))))

for _ in range(m):
    max_i = prices.argmax()
    prices[max_i] = prices[max_i] / 2

total = 0
for price in prices:
    total += math.floor(price)
print(total)

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

    a.sort(reverse = True)
    for i in range(m):

        a[0] = a[0] // 2
        tmp = a[0]

        insert_index = 0
        for j in range(1, n):
            if a[j] > a[0]:
                insert_index = j
            else:
                break

        a.pop(0)
        a.insert(insert_index, tmp)

    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:
import heapq
N, M = [int(_) for _ in input().split()]
A = [-int(_) for _ in input().split()]

heapq.heapify(A)

for _ in range(M):
    a = heapq.heappop(A)
    heapq.heappush(A, -(-a//2))
    if sum(A) == 0:
        break
    
print(-sum(A))

Submission status: Time Limit Exceeded

Solution code:
import math
N,M=map(int,input().split())
l = [int(s) for s in input().split()]

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

print(sum(l))

Submission status: Time Limit Exceeded

Solution code:
N, M, *A, = map(int, open(0).read().split())
A.sort(reverse=True)
Amae = A[:M]
Aushiro = A[M:]
for _ in range(M):
    a = Amae.index(max(Amae))
    Amae[a] = Amae[a] // 2
print(sum(Amae) + sum(Aushiro))

Submission status: Time Limit Exceeded

Solution code:
import sys
import math

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

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

A.sort(reverse=True)
cnt = 1
A[0]=A[0]//2

if N==1:
    while A[0]>0 and cnt<M:
        cnt+=1
        A[0]=A[0]//2
else:
    while cnt<M:
        c=min(M-cnt,int(math.log2(A[0]/A[1])+1))
        cnt+=c
        A[0]=A[0]//(2**c)
        
        b=A[0]
        A[0]=A[1]
        for i in range(2,N):
            if A[i]>b:A[i-1]=A[i]
            else:
                A[i-1]=b
                break

print(sum(A))

Submission status: Time Limit Exceeded

Solution code:
import bisect
N, M = list(map(int, input().split(' ')))
As = list(map(int, input().split(' ')))
# osoi
As = sorted([-a for a in As])
while M:
    hoge = -As.pop(0) // 2
    M -= 1
    while M and As and hoge < As[1]:
        hoge = hoge // 2
        M -= 1
    bisect.insort(As, -hoge)
print(-sum(As))

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

    a.sort(reverse = True)
    for i in range(m):

        a[0] = a[0] // 2
        tmp = a[0]

        insert_index = 0
        for j in range(1, n):
            if a[j] > a[0]:
                insert_index = j
            else:
                break

        for j in range(insert_index):
            a[j] = a[j+1]

        a[insert_index] = tmp

                

    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:
import bisect

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

for m in range(M):
  x = A.pop() // 2
  A.insert(bisect.bisect_left(A, x),x)
print(sum(A))

Submission status: Time Limit Exceeded

Solution code:
import math
N,M=map(int,input().split())
l = [int(s) for s in input().split()]

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

p = 0
for i in range(N):
  p += l[i]
print(p)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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


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

print(sum(A_list))

Submission status: Time Limit Exceeded

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

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

    a.sort(reverse = True)
    for i in range(m):

        a[0] = a[0] // 2
        tmp = a[0]

        insert_index = 0
        for j in range(1, n):
            if a[j] > a[0]:
                insert_index = j

        for j in range(insert_index):
            a[j] = a[j+1]

        a[insert_index] = tmp

                

    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:
import numpy as np
n = list(map(int,input().split()))
a = np.array(list(map(int,input().split())))
for i in range(n[1]):
    a[a.argmax()] = a[a.argmax()]//2 
print(np.sum(a))

Submission status: Time Limit Exceeded

Solution code:
import heapq

x = map(int,raw_input().split())
n=x[0]
m=x[1]
a = map(int, raw_input().split())

def minus(n):
    return float(n*(-1))

def plus(n):
    return int(n*(-1))

a=list(map(minus, a))

for i in range(m):
    heapq.heapify(a)
    a[0]=a[0]/2

a=list(map(plus, a))

print(sum(a))

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect
from bisect import bisect_right
from bisect import bisect_left
from bisect import insort
from bisect import insort_right
from bisect import insort_left

n,m=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
while m>0:
    
    b=a[n-1]//2
    a.pop(n-1)

    insort(a,b)
    m=m-1
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())))

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

Submission status: Time Limit Exceeded

Solution code:
import math
N,M=map(int,input().split())
#print(N,M)
a = list(map(float,input().split()))
#print(a)
a.sort(reverse=True)
#print(a)
k=0
maxa=a[0]/2
while M>0:
#  print(M,k,maxa,a)
  if a[k]>=maxa:
    a[k]=a[k]/2
    M=M-1
  if k==len(a)-1:
    a.sort(reverse=True)
    k=0
    maxa=a[0]
    if maxa<1:
      break
    continue
  if a[k]<a[k+1]:
    if maxa<a[k]:
      maxa=a[k]
    k=k+1
  elif a[k]<maxa:
    if maxa<a[k]:
      maxa=a[k]
    k=k+1
#print(a)
total=0
for t in a:
  total+=int(t)
#  print(t,total)
print(total)

Submission status: Time Limit Exceeded

Solution code:
import math
n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort(reverse = True)
#print(a)
if n == 1:
    for _ in range(m):
        a[0] //= 2
else:
    for _ in range(m):
        a[0]//=2
        b = a[0]
        a.pop(0)
        i = 0
        for _ in range(n-1):
            if a[i] < b:
                a.insert(i, b)
                break
            i+=1
        if i == n-1:
            a.insert(i, b)
        #print(a)

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

n,m = map(int,input().split())
list_a = list(map(int,input().split()))
#b_list = list(map(int,input().split()))
#print(" ".join(map(str,c_list)))
check = 0
list_a.sort(reverse = True)
for i in range(m):
    list_a[np.argmax(list_a[0:6])] = list_a[np.argmax(list_a[0:6])] //2
    check += 1
    if check == 5:
        list_a.sort(reverse = True)
        check = 0
print(sum(list_a))

Submission status: Time Limit Exceeded

Solution code:
import math
N,M=map(int,input().split())
ll = input().split()
l = [int(s) for s in ll]

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

p = 0
for i in range(N):
  p += l[i]
print(p)

Submission status: Time Limit Exceeded

Solution code:
import bisect
N, M = list(map(int, input().split(' ')))
As = list(map(int, input().split(' ')))
As = sorted([-a for a in As])
for i in range(M):
    hoge = -As.pop(0) // 2
    bisect.insort(As, -hoge)
print(-sum(As))

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int,input().split())
lista = list(map(int,input().split()))
#print(n,m)
#print(lista)
lista.sort(reverse=True)
#print(lista)
#print(sum(lista))
count = 0
def discount():
    while True:
        lista[0] = lista[0]//2
        global count
        count +=1
        lista.sort(reverse = True)
        if count == m:
            print(sum(lista))
            break
discount()

Submission status: Time Limit Exceeded

Solution code:
import sys
import math

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

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

A.sort(reverse=True)
cnt = 1
A[0]=A[0]//2

if N==1:
    while A[0]>0 and cnt<M:
        cnt+=1
        A[0]=A[0]//2
else:
    while cnt<M:
        c=int(math.log2(A[0]/A[1])+1)
        cnt+=c
        A[0]=A[0]//(2**c)
        A.sort(reverse=True)
    
print(sum(A))

Submission status: Time Limit Exceeded

Solution code:
import math
import numpy as np
N,M=map(int,input().split())
A=np.array(list(map(int,input().split())))
while M>0:
    M-=1
    A[A.argmax()]/=2
ans=0
for a in A:
    ans+=math.floor(a)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
#import numpy as np
import sys

input = sys.stdin.readline

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

for i in range(M):
    m = max(A)
    A[A.index(m)] //= 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()
b = max(a)
for i in range(0, 31):
    if b < 2**i:
        c = 2**i
        d = i
        break

ref = [2**(i) for i in range(d+1)]
num = []
ama = [0]*len(a)
for i, name in enumerate(a):
    name3 = 0
    for j, name2 in enumerate(ref):
        if name < name2:
            ama[i] += name - name3
            break
        name3 = name2
    num.append(j)

import copy
am = copy.deepcopy(a)
numm = copy.deepcopy(num)
count = m
lenn = len(numm)

while count > 0:
    numm_m = max(numm)
    if numm_m == 0:
         break
    mi = []
    mi_ama = []
    for i, name in enumerate(numm[::-1]):
        if name == numm_m:
            mi.append(lenn-i-1)
            mi_ama.append(ama[lenn-i-1])
    if len(mi) == 1:
        ri = mi[0]
    else:
        mi_ama_max = max(mi_ama)
        ri = mi[mi_ama.index(mi_ama_max)]
    ama[ri] = 0
    numm[ri] -= 1
    am[ri] = am[ri]//2
    count -= 1

print(sum(am))

Submission status: Time Limit Exceeded

Solution code:
import math
N,M=map(int,input().split())
ll = input().split()
l = [int(s) for s in ll]

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

p =0
for i in range(N):
  p += math.floor(l[i])
print(p)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import heapq
# import collection
# import bisect
# import numpy

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

# N = 10**5
# A = [10 for i in range(10**5)]
# M = 10**5

# A = sorted(A)

heapq.heapify(A)

while M > 0:
    i = heapq.nlargest(1, enumerate(A), key=lambda x: x[1])
    A[i[0][0]] = A[i[0][0]] // 2
    M -= 1

print(sum(A))

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int,input().split())
A = [int(i) for i in input().split()]
for i in range(M):
    maxGoods = max(A)
    index = A.index(maxGoods)
    A[index] = int(A[index]/2)
print(sum(A))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import sys
n,m = map(int,input().split())
list_a = list(map(int,input().split()))
#b_list = list(map(int,input().split()))
#print(" ".join(map(str,c_list)))
list_a.sort(reverse = True)
a_max = list_a[0] // 2
list_a[0] = a_max
count = 1
if m == 1:
    print(sum(list_a))
    sys.exit()
if n == 1:
    for i in range(m-1):
        list_a[0]  = list_a[0] // 2
    print(sum(list_a))
    sys.exit()
for i in range(m-1):
    if list_a[np.argmax(list_a[0:count])] < list_a[count]:
        #print(list_a[np.argmax(list_a[0:count])],list_a[count])
        list_a[count] = list_a[count] // 2 
        if count < len(list_a) - 1:
            count += 1
    else:
        list_a[np.argmax(list_a[0:count])] = list_a[np.argmax(list_a[0:count])] // 2
        #print(list_a[np.argmax(list_a[0:count])])
print(sum(list_a))
"""
for i in range(m):
    count = 0
    while count == 0:

        for j in range(n):
            
            if list_a[j] > a_max:
                list_a[j] = list_a[j]//2
                a_max = a_max//2
                count = 1 
                print("c=1")
                print(a_max)
                print(list_a)
                break
        if count == 0:
            a_max -= 1
            print("c=0")
    
print(list_a)
"""

Submission status: Time Limit Exceeded

Solution code:
N,M=map(int,input().split())
import math
ll = input().split()
l = [int(s) for s in ll]

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

p =0
for i in range(N):
  p += math.floor(l[i])
print(p)

Submission status: Time Limit Exceeded

Solution code:
import bisect as ds
import heapq

def heapsort(iterable):
    h = []
    for value in iterable:
        heapq.heappush(h, value)
    return [heapq.heappop(h) for i in range(len(h))]
    
n,m = map(int,input().split())
a = heapsort(map(int,input().split()))
for i in range(m):
    x = a.pop(-1)//2
    ds.insort_left(a,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):
    As.sort(reverse=True)
    As[0] = As[0] // 2

print(sum(As))

Submission status: Time Limit Exceeded

Solution code:
n,m=map(int,input().split())
a=[int(i) for i in input().split()]
b=sorted(a)
c=len(b)



for i in range(0,m):
    b[-1] = b[-1] // 2
    if c != 1:
        if b[-1] < b[-2]:
            b.sort()

print(sum(b))

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())), dtype='int32')
for i in range(m):
    idx = a.argmax()
    a[idx] = a[idx] // 2
print(sum(a))

Submission status: Time Limit Exceeded

Solution code:
import math
N,M=map(int,input().split())
A=list(map(int,input().split()))
while M>0:
    M-=1
    A[A.index(max(A))]/=2
ans=0
for a in A:
    ans+=math.floor(a)
print(ans)

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] = A[0] // 2
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:
tmp = input().split()
N = int(tmp[0])
M = int(tmp[1])
A = input().split()

B = []
for a in A:
    B.append(int(a))


for m in range(M):
    b = max(B)
    B[B.index(b)] = int(B[B.index(b)]/(2**1))

ans = 0
for b in B:
    ans += b

print(ans)

Submission status: Time Limit Exceeded

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]
for i in range(m):
    heapq.heapify(a)
    a[0]=-(-a[0]//2)
ans=0
for i in range(n):
    ans+=a[i]
print(-ans)

Submission status: Time Limit Exceeded

Solution code:
sn,sm = input().split(" ")
n = int(sn)
m = int(sm)
sa = input().split(" ")
l = len(sa)
a = []
 
for i in range(l):
  a.append(int(sa[i]))
 
for i in range(m):  
  ind = a.index(max(a))
  a[ind] = a[ind] //2
  
print(sum(a))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n, m = list(map(int, input().split()))
lisA = [int(i) for i in input().split()]
#print(n, m)
#print(lisA)

lisA.sort(reverse=True)
half0 = lisA[0] / 2
count = 0
for i in range(m):
	if (count > n - 1):
		count = 0
	if (lisA[count] < half0):
		lisA.sort(reverse=True)
		half0 = lisA[0]
		count = 0
	lisA[count] //= 2
	count += 1
print(sum(lisA))