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 = sorted(list(map(int,input().split())),reverse=True)
for i in range(m):
    a[0] = a[0] // 2
    a.sort()
    a.reverse()
print(sum(a))

Submission status: Time Limit Exceeded

Solution code:
import bisect
import math
 
N,M = list(map(int, input().split()))
A = list(map(int, input().split()))
A.sort()
 
for m in range(M):
    A[N-1] = math.floor( A[N-1]/2 )
    temp = A[N-1]
    del A[N-1]
    # 挿入    
    bisect.insort(A, temp)
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] = A[0] // 2
    A.sort(reverse=True)
print(str(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):
    amax = A.index(max(A))
    A[amax] = A[amax] // 2

print(sum(A))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
def f():
  N,M=map(int,input().split())
  A=np.array(list(map(int,input().split())))
  l=[]
  for a in A:
      k=a
      while k>=1:
          l+=[k-k//2]
          k=k//2
  sa=(np.sort(np.array(l))[-M:]).sum()
  print(A.sum()-sa)
f()

Submission status: Time Limit Exceeded

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

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


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

print(sum(A))

Submission status: Time Limit Exceeded

Solution code:
import sys

input = sys.stdin.readline
N, M = map(int, input().split())
A = [int(x) for x in input().split()]
m_idx = A.index(max(A))

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

print(sum(A))

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)
  A.insert(bisect.bisect_left(A, A2), A2)
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))
B.sort(reverse=True)
# print(B)

for m in range(M):
    B[0] = int(B[0]/(2**1))
    B.sort(reverse=True)
    # print(B)
ans = 0
for b in B:
    ans += b

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import math

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

for i in range(m):
    idx = np.argmax(a)
    if a[idx] != 0:
        a[idx] /= 2

for i in range(n):
    a[i] = math.floor(a[i])

print(int(sum(a)))

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int,input().split())
prices = list(map(int,input().split()))
for _ in range(M):
    prices.sort(reverse=True)
    prices[0] //= 2
print(sum(prices))

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int,input().split())
a = list(map(int,input().split()))
if len(a) == 1:
    ans = a[0] * (0.5) ** m
    print(int(ans))
    exit()
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 heapq
import sys
input = sys.stdin.readline

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

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

for i in range(M):
	A.sort(reverse=True)
	max = A.pop(0)
	A.append(int(max/2))

print(sum(A))

Submission status: Time Limit Exceeded

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

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):
    x = A.pop(-1) // 2
    insert_index = bisect.bisect_left(A,x)
    A.insert(insert_index,x)
print(sum(A))

Submission status: Time Limit Exceeded

Solution code:
import sys
import heapq


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


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

    for i in range(M):
        maxaa = -1 * heapq.heappop(AA)
        if max(A) == 0:
            print("0")
            exit()
        heapq.heappush(AA,  maxaa // 2 * (-1))
    print(sum(AA) * (-1))


if __name__ == '__main__':
    main()

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 _ in range(M):
    A[0] = A[0]//2
    A = sorted(A, reverse=True)

print(sum(A))

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int,input().split())
prices = list(map(int,input().split()))
for _ in range(M):
    tgt_index = prices.index(max(prices))
    prices[tgt_index] //= 2
print(sum(prices))

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int,input().split())
a = list(map(int,input().split()))
if len(a) == 1:
    ans = a[0] * (0.5) ** m
    print(int(ans))
    exit()
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:
N,M = map(int, input().split())
money = list(map(int, input().split()))
 
for i in range(M):
  money[money.index(max(money))]//=2
 
print(sum(money))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import bisect

n, m = map(int, input().split())
a = map(int, input().split())
a = sorted(list(a))
for _ in range(m):
    max_num = a.pop()
    bisect.insort(a, max_num // 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>=1:
  b = max(a)
  a[a.index(b)] //2
  
print(sum(a))

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int,input().split())
a = sorted(list(map(int,input().split())),reverse=True) + [0]
max_list = [a[0]]
j = 0
for i in range(m):
    max_index = max_list.index(max(max_list))
    a[max_index] //= 2
    if a[max_index] < a[j+1] and j != n-1:
        j += 1
    max_list = [a[k] for k in range(j+1)]
    if a[max_index] == 0:
        break;
print(sum(a))

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
li = list(map(int, input().split()))
while m >= 1:
    li.sort()
    if len(li) > 1:
        x = 10000
        if li[-2] <= li[-1] // (2 ** (x-1)) and m - x >= 0:
            li[-1] = li[-1] // (2 ** x)
            m -= x
            li.sort()
        x = 5000
        if li[-2] <= li[-1] // (2 ** (x-1)) and m - x >= 0:
            li[-1] = li[-1] // (2 ** x)
            m -= x
            li.sort()
        x = 2500
        if li[-2] <= li[-1] // (2 ** (x-1)) and m - x >= 0:
            li[-1] = li[-1] // (2 ** x)
            m -= x
            li.sort()
        x = 1250
        if li[-2] <= li[-1] // (2 ** (x-1)) and m - x >= 0:
            li[-1] = li[-1] // (2 ** x)
            m -= x
            li.sort()
        x = 625
        if li[-2] <= li[-1] // (2 ** (x-1)) and m - x >= 0:
            li[-1] = li[-1] // (2 ** x)
            m -= x
            li.sort()
        x = 312
        if li[-2] <= li[-1] // (2 ** (x-1)) and m - x >= 0:
            li[-1] = li[-1] // (2 ** x)
            m -= x
            li.sort()
        x = 156
        if li[-2] <= li[-1] // (2 ** (x-1)) and m - x >= 0:
            li[-1] = li[-1] // (2 ** x)
            m -= x
            li.sort()
        x = 78
        if li[-2] <= li[-1] // (2 ** (x-1)) and m - x >= 0:
            li[-1] = li[-1] // (2 ** x)
            m -= x
            li.sort()
        x = 39
        if li[-2] <= li[-1] // (2 ** (x-1)) and m - x >= 0:
            li[-1] = li[-1] // (2 ** x)
            m -= x
            li.sort()
        x = 19
        if li[-2] <= li[-1] // (2 ** (x-1)) and m - x >= 0:
            li[-1] = li[-1] // (2 ** x)
            m -= x
            li.sort()
        x = 9
        if li[-2] <= li[-1] // (2 ** (x-1)) and m - x >= 0:
            li[-1] = li[-1] // (2 ** x)
            m -= x
            li.sort()
        x = 4
        if li[-2] <= li[-1] // (2 ** (x-1)) and m - x >= 0:
            li[-1] = li[-1] // (2 ** x)
            m -= x
            li.sort()
        x = 2
        if li[-2] <= li[-1] // (2 ** (x-1)) and m - x >= 0:
            li[-1] = li[-1] // (2 ** x)
            m -= x
            li.sort()
        x = 1
        if m - x >= 0:
            li[-1] = li[-1] // (2 ** x)
            m -= x
            li.sort()
    else:
        print(li[0] // (2 ** m))
        exit()
print(sum(li))

Submission status: Time Limit Exceeded

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

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

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

print(sum(a))

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(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:
        while A[0]>=A[1] and cnt<M:
            cnt+=1
            A[0]=A[0]//2
          
        b=A[0]
        A.sort(reverse=True)
    
print(sum(A))

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
*a, = sorted(map(int, input().split()), key=lambda x: -x)
for i in range(m):
    tmp = a.pop(0)
    tmp //= 2
    if not a:
        a.append(tmp)
    for j in range(min(len(a), m-i)):
        if tmp > a[j]:
            a.insert(j, tmp)
            break
    else:
        a.append(tmp)

print(sum(a))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import bisect as ds
n,m = map(int,input().split())
a = sorted((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())
A = list(map(int, input().split()))

import heapq

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



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

Submission status: Time Limit Exceeded

Solution code:
# import sys
# import collections

# import bisect
# import math
import numpy as np

# from fractions import gcd

"""Template"""


class IP:
    """
    入力を取得するクラス
    """

    def __init__(self):
        self.input = sys.stdin.readline

    def I(self):
        """
        1文字の取得に使います
        :return: int
        """
        return int(self.input())

    def S(self):
        """
        1文字の取得(str
        :return: str
        """
        return self.input()

    def IL(self):
        """
        1行を空白で区切りリストにします(int
        :return: リスト
        """
        return list(map(int, self.input().split()))

    def SL(self):
        """
        1行の文字列を空白区切りでリストにします
        :return: リスト
        """
        return list(map(str, self.input().split()))

    def ILS(self, n):
        """
        1列丸々取得します(int
        :param n: 行数
        :return: リスト
        """
        return [int(self.input()) for _ in range(n)]

    def SLS(self, n):
        """
        1列丸々取得します（str
        :param n: 行数
        :return: リスト
        """
        return [self.input() for _ in range(n)]

    def SILS(self, n):
        """
        Some Int LineS
        横に複数、縦にも複数
        :param n: 行数
        :return: list
        """
        return [self.IL() for _ in range(n)]

    def SSLS(self, n):
        """
        Some String LineS
        :param n: 行数
        :return: list
        """
        return [self.SL() for _ in range(n)]


class Idea:
    def __init__(self):
        pass

    def HF(self, p):
        """
        Half enumeration
        半分全列挙です
        pの要素の和の組み合わせを作ります。
        ソート、重複削除行います
        :param p: list : 元となるリスト
        :return: list : 組み合わせられた和のリスト
        """
        return sorted(set(p[i] + p[j] for i in range(len(p)) for j in range(i, len(p))))

    def Bfs2(self, a):
        """
        bit_full_search2
        bit全探索の改良版
        全探索させたら2進数のリストと10進数のリストを返す
        :return: list２つ : １個目 2進数(16桁)  2個目 10進数
        """
        # 参考
        # https://blog.rossywhite.com/2018/08/06/bit-search/
        # https://atcoder.jp/contests/abc105/submissions/4088632
        value = []
        for i in range(1 << len(a)):
            output = []

            for j in range(len(a)):
                if self.bit_o(i, j):
                    """右からj+1番目のiが1かどうか判定"""
                    # output.append(a[j])
                    output.append(a[j])
            value.append([format(i, 'b').zfill(16), sum(output)])

        value.sort(key=lambda x: x[1])
        bin = [value[k][0] for k in range(len(value))]
        val = [value[k][1] for k in range(len(value))]
        return bin, val

    def S(self, s, r=0, m=-1):
        """
        ソート関係行います。色々な設定あります。
        :param s: 元となるリスト
        :param r: reversするかどうか 0=False 1=True
        :param m: （2次元配列）何番目のインデックスのソートなのか
        :return: None
        """
        r = bool(r)
        if m == -1:
            s.sort(reverse=r)
        else:
            s.sort(reverse=r, key=lambda x: x[m])

    def bit_n(self, a, b):
        """
        bit探索で使います。0以上のときにTrue出します
        自然数だからn
        :param a: int
        :param b: int
        :return: bool
        """
        return bool((a >> b & 1) > 0)

    def bit_o(self, a, b):
        """
        bit探索で使います。1のときにTrue出すよ
        oneで1
        :param a: int
        :param b: int
        :return: bool
        """
        return bool(((a >> b) & 1) == 1)

    def ceil(self, x, y):
        """
        Round up
        小数点切り上げ割り算
        :param x: int
        :param y: int
        :return: int
        """
        return -(-x // y)

    def ave(self, a):
        """
        平均を求めます
        :param a: list
        :return: int
        """
        return sum(a) / len(a)

    def gcd(self, x, y):
        if y == 0:
            return x
        else:
            return self.gcd(y, x % y)

    def lcm(self, x, y):
        return (x * y) // self.gcd(x, y)


"""ここからメインコード"""


def main():
    # 1文字に省略
    # ip = IP()
    # id = Idea()

    """この下から書いてね"""
    _, m, *a = map(int, open(0).read().split())
    # print([a[np.argmax(a)] // 2 for _ in range(m)])
    for _ in range(m):
        a[np.argmax(a)] //= 2
    print(np.sum(a))


main()

Submission status: Time Limit Exceeded

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

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

print(sum(A))

Submission status: Time Limit Exceeded

Solution code:
import bisect

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

a = sorted(a)

for i in range(m):
    a[n-1] = a[n-1] // 2
    temp = a.pop()
    bisect.insort_left(a, temp)
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]
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))

Submission status: Time Limit Exceeded

Solution code:
N , M = map(int, input().rstrip().split())
 
pricelist = list(map(int, input().split()))
#moneylist = input().rstrip().split()
#pricelist.append(price)
 
for i in range(M):
  pricelist.sort()
  pricelist[N-1] = pricelist[N-1] // 2

print(sum(pricelist))

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
import sys
input = sys.stdin.readline
 
N,M=map(int,input().split())
A=list(map(int,input().split()))
queue=deque(A)
for i in range(M):
    queue.append(max(queue)//2)
    queue.remove(max(queue))
print(sum(queue))

Submission status: Time Limit Exceeded

Solution code:
from collections import deque

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

for m in range(M):
    a=max(A)
    A.remove(a)
    A.append(a//2)
print(sum(A))

Submission status: Time Limit Exceeded

Solution code:
import bisect as ds
n,m = map(int,input().split())
a = sorted((map(int,input().split())))
for i in range(m):
    x = a.pop(-1)//2
    a.insert(ds.bisect_left(a,x),x)
print(sum(a))

Submission status: Time Limit Exceeded

Solution code:
def f():
  N,M=map(int,input().split())
  *A,=map(int,input().split())
  l=[]
  for a in A:
      k=a
      while k>=1:
          l+=[k-k//2]
          k=k//2
  print(sum(A)-sum(sorted(l)[-M:]))
if __name__=="__main__":
  f()

Submission status: Time Limit Exceeded

Solution code:
N,M = map(int, input().split())
ls = list(map(int, input().split()))
ls.sort()
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()))
A2 = sorted(A)
for i in range (M):
  A2[N-1] = int(A2[N-1])//2
  A2 = sorted(A2)
print(sum(A2))

Submission status: Time Limit Exceeded

Solution code:
itemCount, ticketCount = map(int, input().split(' '))
prices = map(int, input().split(' '))


class Product:
    def __init__(self, price):
        self.price = price
        self.ticket = 0
        self.pay = price

    def getPay(self):
        return self.pay // 2 ** self.ticket


def highestProductIndex(products):
    highPrice = 0
    highPriceIndex = 0
    for index, product in enumerate(products):
        if highPrice < product.getPay():
            highPrice = product.getPay()
            highPriceIndex = index

    return highPriceIndex


products = []
for price in prices:
    products.append(Product(price))

for tickenNumber in range(ticketCount):
    index = highestProductIndex(products)
    products[index].ticket += 1

total = 0
for product in products:
    total += product.getPay()

print(total)

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

#.sort()
for i in range(0, M):
    m = max(A)
    n = A.index(m)
    m = m // 2
    A[n] = m
S = 0
for i in A:
    S += i
print(S)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
n, m = map(int, stdin.readline().rstrip().split())
ary = list(map(int, stdin.readline().rstrip().split()))
dp = [[float('inf')] * (m+1) for _ in range(n)]

for i in range(m, -1, -1):
    dp[n-1][i] = ary[n-1] // (2 ** i)
    if n == 1:
        break

if n >= 2:
    for j in range(n-2, -1, -1):
        for i in range(m+1):
            temp = float('inf')
            for k in range(i+1):
                temp = min(temp, dp[j+1][k] + ary[j] // (2 ** (i - k)))
                if temp == 0:
                    break
            dp[j][i] = temp

print(dp[0][m])

Submission status: Time Limit Exceeded

Solution code:
from collections import deque

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

for m in range(M):
    a=max(A)
    A.remove(a)
    A.append(a//2)
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()))+[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))


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

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 numpy as np
import sys
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:
N, M = list(map(int, input().split()))
A = list(map(lambda x: int(x), input().split(' ')))

for _ in range(M):
    diff = 0
    idx = 0
    for i in range(N):
        if (A[i] - A[i]//2) > diff:
            diff = A[i] - A[i]//2
            idx = i
    A[idx] = A[idx] // 2
    
print('{}'.format(sum(A)))

Submission status: Time Limit Exceeded

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

lista.sort(reverse=True)
#print(lista)

if n==1:
    ans=int(sum(lista)/(2**m))

else:
    for i in range(m):
        lista[0]=lista[0]/2
        lista.sort(reverse=True)
    #print(lista)    

    for i in range(n):
        lista[i]=int(lista[i])

    ans=sum(lista)
print(ans)

Submission status: Time Limit Exceeded

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

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

for i in range(m):
  a = aaa.pop() // 2
  insert_index = bisect.bisect_right(aaa, a)
  aaa.insert(insert_index, a)
  
print(sum(aaa))

Submission status: Time Limit Exceeded

Solution code:
from collections import deque

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

A = deque(A)
A = sorted(A)

for i in range(M):
    temp1 = A.index(max(A))
    temp2 = A.pop(temp1) // 2
    A.append(temp2)

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)

m = 0
b = 0
for i in range(M):
    tj = 0
    cnt = 0
    for j in range(N):
        if A[j] == 0:
            continue
        t = A[j] - A[j]//2
        if cnt <= t:
            cnt = t
            tj = j
    A[tj] = A[tj] // 2
    tt = sum(A)
    if b == tt:
        break
    tt = b

print(sum(A))

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int,input().split())
a = [int(i) for i in 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:
import bisect
n,m = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
A = a[(len(a)-m):]
for i in range(m):
    b = A.pop()
    b = b//2
    A.insert(bisect.bisect_left(A,b),b)
print(sum(a[:len(a)-m])+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):
  list.sort(A, reverse=True)
  A[0] = A[0] // 2
print(sum(A))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

sorted_an = sorted(an)
sorted_an.reverse()

discounts = []
for a in sorted_an:
    row = [] # 差が入る
    prev_discounted_price = a
    for i in range(1, m + 1):
        discounted_price = a // (2 ** i)
        if discounted_price == 0:
            row.append(discounted_price - prev_discounted_price)
            break
        row.append(discounted_price - prev_discounted_price)
        prev_discounted_price = discounted_price
    discounts.append(row)

flatten = np.hstack(np.array(discounts))
reversed_discounts = np.sort(flatten)
total_discounts = reversed_discounts[:m]

print(sum(an) + np.sum(total_discounts))

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)
    
for j in range(N):
    A[j] = math.floor(A[j])

print(sum(A))

Submission status: Time Limit Exceeded

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

N, M = map(int, input().split())
A = list(map(int, input().split()))
A = sorted(A, reverse=True)
for i in range(M):
    ans = int(A[0] / 2)
    A[0] = ans
    A = sorted(A, reverse=True)
sum = 0
for a in A:
    sum += a
print(sum)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
import sys

input = sys.stdin.readline

def main():
  n, m = map(int, input().split())
  prices = map(int, input().split())
  
  priceMap = defaultdict(lambda : 0)
  
  for price in prices:
    priceMap[price] += 1
  
  for _ in range(m):
    keys = priceMap.keys()
    maxPrice = max(keys)
    priceMap[maxPrice] -= 1
    if priceMap[maxPrice] == 0:
      del(priceMap[maxPrice])
    newPrice = maxPrice // 2
    priceMap[newPrice] += 1
  
  total = 0
  for price, num in priceMap.items():
  	total += price * num
  print(total)
  
if __name__ == "__main__":
  main()

Submission status: Time Limit Exceeded

Solution code:
import bisect


N,M=map(int,input().split())
la=list(map(int,input().split()))
la.sort()
for i in range(M):
    #la.sort()
    #la[N-1]/=2
    ll=la[N-1]/2
    la.pop()
    #la.insert(nibutan(0,N-2,la,ll),ll)
    bisect.insort_left(la,ll,0,N-1)

ans=0
for i in range(N):
    ans+=int(la[i])
print(ans)

Submission status: Time Limit Exceeded

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

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

print (sum(lst))

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 i in range(M):
    u=A.argmax()
    A[u]= A[u]//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()))
a.sort(reverse=True)
o=[2**i for i in range(1,15)]
for i in range(m):
    if len(a) <= 2:
        print(0)
        exit()
    if math.floor(a[0] / a[1]) in o:
        a[0] = math.floor(a[0] / math.floor(a[0] / a[1]))
    else:
        a[0]=math.floor(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 = sorted(A)
if N == 1:
  a = A[0]
  for j in range(M):
    a = a//2
  print(a)
elif N > 1:  
  for i in range(M):
    aa = A.index(max(A))
    A[aa] = A[aa]//2
  print(sum(A))

Submission status: Time Limit Exceeded

Solution code:
import math
[N,M]=list(map(int,input().split()))

A=[""]*N

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

A.sort()
#print(A)

for i in range(M):
    A[N-1]=math.floor(A[N-1]/2)  
    if A[N-1]<A[N-2]:      
        for j in range(N-2,-1,-1):
            if A[j-1]<=A[N-1] and A[j]>=A[N-1]:
                A.insert(j,A[-1])
                del A[-1]
                break
    #A.sort()
    #print(A)


print(sum(A))

Submission status: Time Limit Exceeded

Solution code:
def bubble_sort(arr):
    change = True
    while change:
        change = False
        for i in range(len(arr) - 1):
            if arr[i] > arr[i + 1]:
                arr[i], arr[i + 1] = arr[i + 1], arr[i]
                change = True
    return arr

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

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

A = bubble_sort(A)

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

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

    if A[-1] < A[-2]:
        A = bubble_sort(A)
        #popA = A.pop(0)

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

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

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=sum(l)

print(total)

Submission status: Time Limit Exceeded

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

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

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

a=list(map(int,input().split()))
aorg=a[:]
waribiki=[0]*n

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

total=0
for i in range(n):
  if waribiki[i]!=0:
    aorg[i]=aorg[i]//(2**waribiki[i])
  total+=aorg[i]
print (total)

Submission status: Time Limit Exceeded

Solution code:
import bisect
from collections import deque

N,M=map(int,input().split())
A=[int(_) for _ in input().split()]
A.sort()
A=deque(A)

for m in range(M):
    a=A.pop()//2
    insert_index = bisect.bisect(A,a)
    A=list(A)
    A.insert(insert_index,a)
    A=deque(A)
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[prices.index(max(prices))]//=2
print(sum(prices))

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(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()]
for i in range(m):
  b = max(a)
  c = a.index(b)
  a[c] = b//2
  if sum(a) == 0:
    print(0)
    exit()
print(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):
    i = a.index(max(a))
    a[i] = a[i] // 2
print(sum(a))