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 sys
input=sys.stdin.readline
from math import floor

N,M = (int(x) for x in input().rstrip('\n').split())
As = [int(x) for x in input().rstrip('\n').split()]
As = sorted(As)
for _ in range(M):
  d = As[-1]
  As[-1] = d/2
  As = sorted(As)
print(sum(floor(x) for x in As))

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(m):
    a.sort()
    a[-1] //= 2

sum = 0
for i in a:
    sum += i

print(int(sum))

Submission status: Time Limit Exceeded

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

N,M = (int(x) for x in input().rstrip('\n').split())
As = [int(x) for x in input().rstrip('\n').split()]
As = sorted(As)
for _ in range(M):
  d = As[-1]
  As[-1] = d//2
  As = sorted(As)
print(sum(As))

Submission status: Time Limit Exceeded

Solution code:
class max_heap():
    def __init__(self,arr):
        self.array = arr
        self.build_heap()

    def heapify(self,i):
        left = 2 * i + 1
        right = 2 * i + 2
        length = len(self.array) - 1
        biggest = i
        
        if left <= length and self.array[i] < self.array[left]:
            biggest = left
        if right <= length and self.array[biggest] < self.array[right]:
            biggest = right
        if biggest != i:
            self.array[i], self.array[biggest] = self.array[biggest], self.array[i]
            self.heapify(biggest)

    def build_heap(self):
        for i in reversed(range(len(self.array)//2)):
            self.heapify(i)
            
    def heappop(self):
        self.array[0], self.array[-1] = self.array[-1], self.array[0]
        res = self.array.pop()
        self.heapify(0)
        return res
    
    def heappush(self,n):
        self.array.append(n)
        self.build_heap()

N, M = map(int,input().split())
A = list(map(int,input().split()))
heap = max_heap(A)
for i in range(M):
    num = heap.heappop()//2
    heap.heappush(num)
print(sum(heap.array))

Submission status: Time Limit Exceeded

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

for i in range(M):
    ind = np.argmax(A)
    A[ind] = A[ind]//2

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):
    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=list(map(int,input().split()))
A.sort()

from bisect import insort
while M>0:
  a = A.pop()
  a /= 2
  insort(A,a)
  M-=1
ans = 0
for a in A:
  ans += int(a)
print(ans)

Submission status: Time Limit Exceeded

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

from bisect import insort
while M>0:
  a = A.pop(-1)
  a /= 2
  insort(A,a)
  M-=1
ans = 0
for a in A:
  ans += int(a)
print(ans)

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

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

a.sort()

ans = sum(a)
for i in range(m):
    tmp = a.pop()
    ans -= tmp
    cost = math.floor(tmp/2)
    ans += cost
    idx = bisect.bisect_left(a,cost)
    a.insert(idx,cost)

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys
from collections import Counter
from math import ceil

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.buffer.readline


class VanEmdeBoasTree:
    def __init__(self, size):
        self.universe_size = 1 << size.bit_length()
        self.minimum = -1
        self.maximum = -1
        self.summary = None
        self.cluster = {}
    
    def __high(self, x):
        return x // ceil(self.universe_size ** 0.5)
    
    def __low(self, x):
        return x % ceil(self.universe_size ** 0.5)
    
    def __generate_index(self, x, y):
        return x * ceil(self.universe_size ** 0.5) + y
    
    def __empinsert(self, key):
        self.minimum = self.maximum = key
    
    def insert(self, key):
        if self.minimum == -1:
            self.minimum = self.maximum = key
        else:
            if key < self.minimum:
                self.minimum, key = key, self.minimum
            if 2 < self.universe_size:
                if self.__high(key) not in self.cluster:
                    self.cluster[self.__high(key)] = VanEmdeBoasTree(ceil(self.universe_size ** 0.5))
                    if self.summary is None:
                        self.summary = VanEmdeBoasTree(ceil(self.universe_size ** 0.5))
                    self.summary.insert(self.__high(key))
                    self.cluster[self.__high(key)].__empinsert(self.__low(key))
                else:
                    self.cluster[self.__high(key)].insert(self.__low(key))
            if self.maximum < key:
                self.maximum = key
    
    def is_member(self, key):
        if self.minimum == key or self.maximum == key:
            return True
        elif self.universe_size == 2:
            return False
        else:
            if self.__high(key) in self.cluster:
                return self.cluster[self.__high(key)].is_member(self.__low(key))
            else:
                return False
    
    def successor(self, key):
        # バグらせてるっぽい
        if self.universe_size == 2:
            if key == 0 and self.maximum == 1:
                return 1
            else:
                return -1
        elif self.minimum != -1 and key < self.minimum:
            return self.minimum
        else:
            max_incluster = -1
            if self.__high(key) in self.cluster:
                max_incluster = self.cluster[self.__high(key)].maximum
            if max_incluster != -1 and self.__low(key) < max_incluster:
                offset = self.cluster[self.__high(key)].successor(self.__low(key))
                return self.__generate_index(self.__high(key), offset)
            else:
                succ_cluster = -1
                if self.summary.successor is not None:
                    succ_cluster = self.summary.successor(self.__high(key))
                if succ_cluster == -1:
                    return -1
                else:
                    offset = self.cluster[succ_cluster].minimum
                    return self.__generate_index(succ_cluster, offset)
    
    def predecessor(self, key):
        if self.universe_size == 2:
            if key == 1 and self.minimum == 0:
                return 0
            else:
                return -1
        elif self.maximum != -1 and self.maximum < key:
            return self.maximum
        else:
            min_incluster = -1
            if self.__high(key) in self.cluster:
                min_incluster = self.cluster[self.__high(key)].minimum
            if min_incluster != -1 and min_incluster < self.__low(key):
                offset = self.cluster[self.__high(key)].predecessor(self.__low(key))
                return self.__generate_index(self.__high(key), offset)
            else:
                pred_cluster = -1
                if self.summary is not None:
                    pred_cluster = self.summary.predecessor(self.__high(key))
                if pred_cluster == -1:
                    if self.minimum != -1 and self.minimum < key:
                        return self.minimum
                    else:
                        return -1
                else:
                    offset = self.cluster[pred_cluster].maximum
                    return self.__generate_index(pred_cluster, offset)
    
    def delete(self, key):
        if self.minimum == self.maximum:
            self.minimum = self.maximum = -1
            return True
        elif self.universe_size == 2:
            if key == 0:
                self.minimum = 1
            else:
                self.minimum = 0
            self.maximum = self.minimum
            return False
        else:
            if key == self.minimum:
                first_cluster = self.summary.minimum
                key = self.__generate_index(first_cluster, self.cluster[first_cluster].minimum)
                self.minimum = key
            flg0 = self.cluster[self.__high(key)].delete(self.__low(key))
            if flg0:
                del self.cluster[self.__high(key)]
                flg1 = self.summary.delete(self.__high(key))
                if key == self.maximum:
                    if flg1:
                        self.maximum = self.minimum
                    else:
                        max_insummary = self.summary.maximum
                        self.maximum = self.__generate_index(max_insummary, self.cluster[max_insummary].maximum)
            elif key == self.maximum:
                self.maximum = self.__generate_index(self.__high(key), self.cluster[self.__high(key)].maximum)


def solve():
    N, M = map(int, rl().split())
    A = list(map(int, rl().split()))
    
    veb = VanEmdeBoasTree(10 ** 9)
    for ai in A:
        veb.insert(ai)
    
    counter = Counter(A)
    for _ in range(M):
        maximum = veb.maximum
        counter[maximum] -= 1
        if counter[maximum] == 0:
            veb.delete(maximum)
        if counter[maximum // 2] == 0:
            veb.insert(maximum // 2)
        counter[maximum // 2] += 1
    
    ans = 0
    for key, val in counter.items():
        ans += key * val
    print(ans)


if __name__ == '__main__':
    solve()

Submission status: Time Limit Exceeded

Solution code:
# from pprint import pprint
# import math
# import collections

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

for _m in range(m):
    a = sorted(a, reverse=True)

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

ans = sum(a)
print(ans)

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([int(a) for a in A]))

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python
# coding: utf-8

# In[12]:


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


# In[13]:


for m in range(M):
    idx = A.index(max(A))
    A[idx] /= 2
ans = sum([x//1 for x in A])
print(int(ans))


# In[ ]:

Submission status: Time Limit Exceeded

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

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

print(sum(prices))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

a = list(map(int,input().split()))
res = sum(a)
dis = 0
for v in range(M):
    a.sort(reverse=True)
    dis += a[0] - a[0]//2
    a[0] //=2
print(res-dis)

Submission status: Time Limit Exceeded

Solution code:
import math

n,m=map(int,input().split())
A = list(map(int, input().split()))
B = [0]*n
B = sorted(A, reverse = True)
c = 0
for i in range(m):
  B[0] = math.floor(B[0]/2)
  for j in range(n-1):
    if(B[j] < B[j+1]):
      c = B[j+1]
      B[j+1] = B[j]
      B[j] = c
    else:
      break
print(sum(B))

Submission status: Time Limit Exceeded

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

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

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

print(s)

Submission status: Time Limit Exceeded

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

for i in range(m):
    a[0] //= 2
    if (len(a) > 1):
        if (a[0] < a[1]):
            a.sort(reverse=True)

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

print(s)

Submission status: Time Limit Exceeded

Solution code:
N ,M = map(int, input().split())
A_list = [int(i) * (-1) for i in input().split()]


import heapq
for i in range(M):
    heapq.heapify(A_list)
    x = heapq.heappop(A_list) / 2
    heapq.heappush(A_list, (-1)*int(-x))

print(-sum(A_list))

Submission status: Time Limit Exceeded

Solution code:
from fractions import Fraction
from math import log, ceil
import heapq

(n, m), aa = [list(map(int, s.split())) for s in open(0)]
aa = [-Fraction(a) for a in aa]

heapq.heapify(aa)

while m:
    m1 = heapq.heappop(aa)
#     print(f'{m=},{m1=}')
    if len(aa):
        m2 = heapq.nsmallest(1, aa)[0]
        use = min(max(ceil(log(m1/m2)/log(2)), 1), m)
#         print(f'{m2=},{use=}')
    else:
        use = min(max(ceil(log(-m1)/log(2)), 1), m)
#         print(f'else, {use=}')
#         print(f'{ceil(log(-m1)/log(2))=}')
#     print(f'{m1/Fraction(2**use)}')
    heapq.heappush(aa, m1 / Fraction(2**use))
    m -= use
    if -heapq.nsmallest(1, aa)[0] < 1:
        break

aa = [int(-a) for a in aa]

print(sum(aa))

Submission status: Time Limit Exceeded

Solution code:
from fractions import Fraction

import heapq

(m, n), aa = [list(map(int, s.split())) for s in open(0)]

aa = [-Fraction(a) for a in aa]

heapq.heapify(aa)

for _ in range(n):
    mx = heapq.heappop(aa)
    heapq.heappush(aa, mx / Fraction(2))

aa = [int(-a) for a in aa]

print(sum(aa))

Submission status: Time Limit Exceeded

Solution code:
from math import floor
n, m = map(int, input().split())
list_A = list(map(int, input().split()))
for i in range(m):
  MAX = max(list_A)
  Index = list_A.index(MAX)
  list_A[Index] = floor(MAX/2)
  m -= 1
print(sum(list_A))

Submission status: Time Limit Exceeded

Solution code:
from math import floor
n, m = map(int, input().split())
list_A = list(map(int, input().split()))
list_A.sort(reverse = True)
while m > 0:
  MAX = max(list_A)
  Index = list_A.index(MAX)
  list_A[Index] = floor(MAX/2)
  m -= 1
print(sum(list_A))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int, input().split())
a = list(map(int, input().split()))
for _ in range(m):
    a.sort(reverse=True)
    amax = a[0]
    a.pop(0)
    a.append(amax//2)
print(sum(a))

Submission status: Time Limit Exceeded

Solution code:
def main():
    n, m = map(int, input().split())
    a = [int(x) for x in input().split()]
    a.sort(reverse=True)
    ans = sum(a)
    diff = 0
    for i in range(1, m+1):
        a_i = a[:i]
        a_m = max(a_i)
        diff += a_m  - a_m // 2
        a_m_i = a_i.index(a_m)
        a[a_m_i] = a[a_m_i] // 2
    ans -= diff
    print(ans)
    
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import math
n,m = map(int,input().split())
price = list(map(int,input().split()))
price.sort(reverse=True)
while m != 0:
    tmp = max(price)
    tmp = tmp//2
    price[price.index(max(price))] = tmp
    m -= 1
print(sum(price))

Submission status: Time Limit Exceeded

Solution code:
import math
n,m = map(int,input().split())
price = list(map(int,input().split()))
price.sort(reverse=True)
real_price = 0
while m != 0:
    price[0] = price[0]//2
    price.sort(reverse=True)
    m -= 1

#for i in range(n):
#    real_price += math.floor(price[i])
#print(real_price)
print(sum(price))

Submission status: Time Limit Exceeded

Solution code:
import math
n,m = map(int,input().split())
price = list(map(int,input().split()))
price.sort(reverse=True)
real_price = 0
while m != 0:
    price[0] = price[0]/2
    price.sort(reverse=True)
    m -= 1

for i in range(n):
    real_price += math.floor(price[i])
print(real_price)

Submission status: Time Limit Exceeded

Solution code:
import bisect

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

A = list(map(int, input().split()))
A.sort()
#print(A)

for _ in range(M):
    a = int(A.pop()/2)
    bisect.insort_left(A, a)

print(sum(A))

Submission status: Time Limit Exceeded

Solution code:
import bisect

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

A = list(map(int, input().split()))
A.sort()
#print(A)

for _ in range(M):
    a = A.pop()/2
    bisect.insort_left(A, a)

print(sum(list(map(int, A))))

Submission status: Time Limit Exceeded

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

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

print(sum(A))

Submission status: Time Limit Exceeded

Solution code:
import bisect
from collections import deque
import sys

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

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

    for _ in range(M):
        max_value = que.pop()
        bisect.insort_right(que,max_value // 2)

    print(sum(que))

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import bisect
from collections import deque

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

for _ in range(M):
    max_value = que.pop()
    bisect.insort_right(que,max_value // 2)

print(sum(que))

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(1,M+1):
    max_value = max(A[:i])
    max_index = A.index(max_value)
    A[max_index] = max_value // 2

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

print(sum(A))

Submission status: Time Limit Exceeded

Solution code:
from collections import deque

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

A = deque(sorted(A, reverse=True))
for _ in range(M):
  x = A.popleft()//2
  for i, a in enumerate(A):
    if x >= a:
      A.insert(i, x)
      break
  else:
    A.append(x) 
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 i in range(m):
  a[0]//=2
  #a=sorted(a,reverse=True)
  for j in range(n-1):
    if a[j]>a[j+1]:
      break
    k=a[j]
    a[j]=a[j+1]
    a[j+1]=k
  if a[0]==0:
    break
ans=0
for i in a:
  ans+=i
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N,M = map(int,input().split())
A = list(map(int,input().split()))
# 解法 bisectとsort(最初だけ)を使う
# dequeでbisectって使えんのかなぁ？
A.sort()
from collections import deque
A = deque(A)
import bisect
for i in range(M):
    a = A.pop()
    new = a/2
    bisect.insort_left(A,new)   # やってることはA.sort(bisect.bisect_left(A,new),new)
import numpy as np
A = np.array(A,dtype=np.int64)
print(A.sum())

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[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()))

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

print(sum(A))

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python
import sys
from collections import deque, defaultdict
from itertools import combinations, combinations_with_replacement
import bisect
from math import factorial, sqrt, log, ceil, floor
sys.setrecursionlimit(1000000)


def main():
    #N, M = map(int, input().split())
    #N, K = map(int, input().split())

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

    As = sorted(As)

    for i in range(M):
        A = As.pop(-1)
        A = A // 2
        bisect.insort_left(As, A)

    total = sum(As)
    print(total)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import bisect

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

def ii():
    return int(input())

def main():
    N, M = mi()
    A = list(mi())
    A.sort()
    for i in range(M):
        t = A.pop()
        t = t>>1
        bisect.insort_left(A, t)
    print(sum(A))


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
N,M=map(int,input().split())
L=list(map(int,input().split()))
for j in range(M):
  R=[i for i, v in enumerate(L) if v == max(L)]
  L[R[0]]//=2
print(sum(L))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

i=0
while(1):
  while a[0]>=a[1]:
    a[0]=a[0]/2
    i=i+1
    if i==m:
      break
  if i==m:
    break
  a.sort(reverse=True)
 
ans=0
for i in range(n):
  ans=ans+int(a[i])
print(ans)

Submission status: Time Limit Exceeded

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

for x in range(M):
    A[0] = A[0] // 2
    A = sorted(A, reverse=True)
print(sum(A))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N, M = [int(x) for x in input().split()]
A = np.array([int(x) for x in input().split()])

while M > 0:
    M -= 1
    A[A.argmax()] //= 2
print(sum(A))

Submission status: Time Limit Exceeded

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

while M > 0:
    index = A.index(max(A))
    A[index] //= 2
    M -= 1

print(sum(A))

Submission status: Time Limit Exceeded

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

for _ in range(M):
    x = al.pop()
    bisect.insort(al, x//2)

print(sum(al))

Submission status: Time Limit Exceeded

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

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

print(sum(al))

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_dic = {A[i]: i for i in range(N)} #value: idx
A_items = [[A[i], i] for i in range(N)]
A_items = sorted(A_items, reverse=True)
# その時の最大のAに１つ使う　これを繰り返す
total = 0
rest = M
if N == 1:
    while rest > 0:
        rest -= 1
        A[0] //= 2
    total = A[0]
elif N == 2:
    while rest > 0:
        rest -= 1
        if A[0] >= A[1]:
            A[0] //= 2
        else:
            A[1] //= 2
    total = A[0] + A[1]
else:
    while rest > 0:
        temp_idx = A_items[0][1]
        while A_items[0][0] >= A_items[1][0]:
            rest -= 1
            A_items[0][0] //= 2
            A[temp_idx] //= 2
        idx = 2
        while A_items[0][0] < A_items[idx][0]:
            idx += 1
            if idx >= N-1:
                break
        u, v = A_items[0], A_items[idx-1]
        A_items[idx-1] = u
        A_items[0] = v
    total = sum(A)

print(total)

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
A = list(map(int, input().split()))
# A_dic = {A[i]: i for i in range(N)} #value: idx
A_items = [[A[i], i] for i in range(N)]
A_items = sorted(A_items, reverse=True)
# その時の最大のAに１つ使う　これを繰り返す
ans = [0]*N # iに使うチケットの枚数
total = 0
rest = M
if N == 1:
    while rest > 0:
        rest -= 1
        A[0] //= 2
    total = A[0]
elif N == 2:
    while rest > 0:
        rest -= 1
        if A[0] >= A[1]:
            A[0] //= 2
        else:
            A[1] //= 2
    total = A[0] + A[1]
else:
    while rest > 0:
        temp_idx = A_items[0][1]
        while A_items[0][0] >= A_items[1][0]:
            ans[temp_idx] += 1
            rest -= 1
            A_items[0][0] //= 2
            A[temp_idx] //= 2
        
        idx = 2
        while A_items[0][0] < A_items[idx][0]:
            idx += 1
            if idx >= N-1:
                break
        u, v = A_items[0], A_items[idx-1]
        A_items[idx-1] = u
        A_items[0] = v
    total = sum(A)

print(total)

Submission status: Time Limit Exceeded

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

a.sort(reverse=True)

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

print(sum(a))

Submission status: Time Limit Exceeded

Solution code:
def solve():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    
    for _ in range(M):
        A.sort()
        A[N-1] = A[N-1] // 2
        if A[N-1] < A[N-2]:
            A[N-1], A[N-2] = A[N-2], A[N-1]
    
    return sum(A)

print(solve())

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
    if n != 1 and a[-1] < a[-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()
for i in range(m):
    a[-1] //= 2
    a.sort()
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()

for i in range(m):
    t = a[n-1]//2
    index = bisect.bisect_left(a,t)
    a.insert(index,t)

a=a[:n]
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()
for i in range(m):
  c=math.floor(a[-1]/2)
  a[-1]=c
  a.sort()
 
sum=0
for i in range(n):
  sum+=a[i]
  
print(sum)

Submission status: Time Limit Exceeded

Solution code:
import math
n,m=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
for i in range(m):
  c=math.floor(max(a)/2)
  a.remove(a[-1])
  a.append(c)
  a.sort()
 
sum=0
for i in range(n):
  sum+=a[i]
  
print(sum)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Wed Jun  3 18:35:23 2020

@author: NEC-PCuser
"""

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

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

ans = 0
for j in range(len(A)):
    ans += A[j]

print(ans)

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):
    a = A.pop() / 2
    bisect.insort(A, a)
ans = 0
for a in A:
    ans += a // 1
print(int(ans))

Submission status: Time Limit Exceeded

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


prod = sorted(prod,reverse=True)

for _ in range(m):
    prod[0]=prod[0]//2

    prod=sorted(prod,reverse=True)



print(sum(prod))

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

print(sum(a))

Submission status: Time Limit Exceeded

Solution code:
import bisect


def m():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    A.sort()
    while M > 0:
        tmp = A[N - 1] = A[N - 1] >> 1
        M -= 1
        i = bisect.bisect_left(A, A[N - 1])
        A.insert(i, tmp)
        A.pop()
    return sum(A)
print(m())

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:
from sys import stdin, setrecursionlimit
from bisect import insort


def main():
    input = stdin.buffer.readline
    n, m = map(int, input().split())
    a = list(map(int, input().split()))
    a.sort()

    for _ in range(m):
        tmp = a[n - 1] // 2
        insort(a, tmp)

    print(sum(a[:n]))


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    n, m = map(int, input().split())
    a = list(map(int, input().split()))

    for _ in range(m):
        a.sort()
        a[-1] = a[-1] // 2

    print(sum(a))


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()

Submission status: Time Limit Exceeded

Solution code:
import bisect

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

arr.sort()

for _ in range(m):
    q = arr.pop()
    bisect.insort_right(arr, q // 2)

print(sum(arr))

Submission status: Time Limit Exceeded

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

arr.sort()

for _ in range(m):
    q = arr.pop()
    q = q // 2
    bisect.insort_left(arr, q)

print(sum(arr))

Submission status: Time Limit Exceeded

Solution code:
import bisect
n,m=[int(x) for x in input().rstrip().split()]
a=[int(x) for x in input().rstrip().split()]
a.sort()

while(m):
  m-=1
  now=a.pop()
  a.append(now//2)
  a.sort()

print(sum(a))

Submission status: Time Limit Exceeded

Solution code:
import bisect
n,m=[int(x) for x in input().rstrip().split()]
a=[int(x) for x in input().rstrip().split()]
a.sort()

while(m):
  m-=1
  now=a.pop()
  ind=bisect.bisect_left(a,(now//2))
  a.insert(ind,(now//2))

print(sum(a))

Submission status: Time Limit Exceeded

Solution code:
import bisect
n,m=[int(x) for x in input().rstrip().split()]
a=[int(x) for x in input().rstrip().split()]
a.sort()
ans=0

while(m):
  m-=1
  now=a.pop()
  ind=bisect.bisect_left(a,int(now/2))
  a.insert(ind,int(now/2))

print(sum(a))