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: Runtime Error

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

sortedA = sorted(a, reverse=True)

x = 0
y = 0
me = 0
while True:
    while sortedA[y] > sortedA[y + 1] and x != m:
        sortedA[y] /= 2
        x += 1
        if me < sortedA[y]:
            me = sortedA[y]
    y += 1
    if me > sortedA[y]:
        y = 0

    if x == m:
        count = 0
        for i in range(n):
            count += math.floor(sortedA[i])

        print(count)
        sys.exit()

count = 0
for i in range(n):
    count += math.floor(sortedA[i])

print(count)

Submission status: Runtime Error

Solution code:
import math
n, m = map(int, input().split())
a_array = list(map(int, input().split()))
a_array.sort(reverse=True)
total_skip_count = 0
## for x in range(n):
for x in range(m):
    skip_count = 0
    ## 回数券分ループ
    while total_skip_count < m and a_array[n - 2 - skip_count:n - 1] and a_array[x] >= max(a_array[n - 2 - skip_count:n - 1]) / 2:
        a_array[x] = math.floor(a_array[x] / 2)
        skip_count += 1
        total_skip_count += 1
        if x + skip_count == m:
            break
print(int(sum(a_array)))

Submission status: Runtime Error

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

a = input()
list1 = list(map(int,a.split()))
list1.sort()
list1.reverse()
i = 0
s = math.floor(list1[0]/2)

if n == 1:
    print(math.floor(list1[0]/(2**m)))
    exit()

while True:
    while True:
        if list1[i] < s or m == 0:
            break
        list1[i] = math.floor(list1[i]/2)
        m -= 1
        i += 1
    if m == 0:
        break
    list1.sort()
    list1.reverse()
    s = math.floor(list1[0]/2)
    i = 0
print(sum(list1))

Submission status: Runtime Error

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

A = sorted(A)[::-1]
a = 0
for i in range(M):
    A[a] = A[a] // 2
    if a > 0:
        if A[a-1] > A[a]:
            a -= 1
    if a+1 <= len(A)-1:
        if A[a] < A[a+1]:
            a += 1
            if A[a] < A[a+1]:
                a += 1
        if a+2 <= len(A)-1:
            if A[a] in [A[a+1], A[a+1]+1]:
                if A[a] < A[a+2]:
                    a += 2

print(sum(A))

Submission status: Runtime Error

Solution code:
import math

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

#B=list(map(lambda x: int(math.log2(x)), A))

#どこに何枚適用するか
D=[0 for _ in range(N)]

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

print(sum(A))

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(int(1e6))
import math

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

if N > M:
    A.sort(reverse=True)
    A1 = A[0:M]
    A2 = A[M:]
    for _ in range(M):
        i = A1.index(max(A1))
        A1[i] = A1[i] // 2
    print(sum(A1, A2))
else:
    for _ in range(M):
        i = A.index(max(A))
        A[i] = A[i] // 2
    print(sum(A))

Submission status: Runtime Error

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

ans = sum(a)

for i in range(m):
  if max(a) % 2 == 0:
    ans -= max(a) // 2
  else:
    ans -= ((max(a) // 2)+1)
    
  a.remove(max(a))
 
print(ans)

Submission status: Runtime Error

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

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: Runtime Error

Solution code:
import copy
n,m=map(int, input().split())
a=sorted([int(i) for i in input().split()],reverse=True)
if n==1:
    print(a[0]//(2**m))
    exit()
def solve(cnt, coupon, now):
    ans = 10 ** 10
    if cnt==m:
        tmp=0
        for i in range(n):
            tmp+=a[i]//(2**coupon[i])
        return tmp
    nowcp=coupon
    for i in range(1,m-cnt+1):
        temp=copy.copy(nowcp)
        temp[now]=i
        ans=min(ans,solve(cnt+i,temp, now+1))
    return ans
print(solve(0,[0 for _ in range(n)], 0))

Submission status: Runtime Error

Solution code:
import numpy as np
N, M = map(int, input().split())
items = np.array(list(map(int, input().split())))
amari = (M-10)%2
if M > 10:
    for i in range((M-10)/2):
        items[items.argmax()]/=4
    for i in range(10+amari):
        items[items.argmax()]/=2
else:
    for i in range(M):
        items[items.argmax()]/=2
print(round(np.sum(items)))

Submission status: Runtime Error

Solution code:
import math

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

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

Submission status: Runtime Error

Solution code:
import bisect
import numpy as np

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

a.sort()

for i in range(m):
  x=a.pop(n-1)/2
  insert_index = bisect.bisect_left(a,x)
  a.insert(insert_index,x)

print(int(sum(np.round(a, 0))))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import bisect
n,m = [int(i) for i in input().split()]
l = sorted([int(i) for i in input().split()])
l2 = []
[bisect.insort(l,l.pop()//2,0,n) for _ in range(m)]
print(sum(l[0:n]))

Submission status: Runtime Error

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

    for i in range(N):
        if i == N-1:
            v = 2
        else:
            v = Al[i]//Al[i+1]

        sq = 2
        while v//(2**sq) > 2:
            sq += 1
        
        if M < sq:
            sq = M
        
        M -= sq
        Al[i] = round(Al[i]/2**sq)
        if M == 0:
            print(sum(Al))
            exit()

Submission status: Runtime Error

Solution code:
LL = [int(i) for i in input().split()]
N = LL[0]
M = LL[1]

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


for c in range(M//2):
    A_price = sorted(A_price,reverse=True)
    A_price[0] = A_price[0] //2
    if A_price[0] >= A_price[1]:
        A_price[0] = A_price[0] //2
    else:
        A_price[1] = A_price[1] //2

if M % 2 == 0:
    print(sum(A_price))
else:
    A_price = sorted(A_price,reverse=True)
    A_price[0] = A_price[0] // 2
    print(sum(A_price))

Submission status: Runtime Error

Solution code:
n, m = map(int, input().split())
inl = [map(int, input().split())]
for i in range(m):
  mx = 0
  th = 0
  for j in range(n):
    if inl[j] > mx:
      mx = inl[j]
      th = j
  inl[j] = int(inl[j]/2)
sum = 0
for k in range(n):
  sum += inl[k]
print(sum)

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
A = sorted(list(map(int, input().split())), reverse=True)
top, bottom = 0, M-1

if len(A) == 1:
    for _ in range(M):
        A[0] //= 2
else:
    for _ in range(M):
        A[top] //= 2
        if A[top] >= A[bottom]:
            if bottom > top >= 0:
                bottom -= 1
            continue
        else:
            top += 1
print(sum(A))

Submission status: Runtime Error

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

print(sum(A))

Submission status: Runtime Error

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

for i in range(m):
    while a[0] >= a[1]:
        a[0] = a[0]//2
    a.sort()
print(sum(a))

Submission status: Runtime Error

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

Alist = sorted(Alist, reverse=True)

cnt = 0
while cnt <= M:
    cnt += 1
    Alist[0] = Alist[0]//2
    if Alist[0] <= Alist[1]:
        Alist = sorted(Alist, reverse=True)

print(sum(Alist))

Submission status: Runtime Error

Solution code:
from math import floor
n,m=map(int,input().split())
a=list(map(int,input().split()))
a.sort(reverse=True)
while m>0:
  a[0]/=2
  m-=1
  if a[0]<a[1]:
    a.sort(reverse=True)
for i in range(n):
  a[i]=math.floor(a[i])
print(sum(a))

Submission status: Runtime Error

Solution code:
N,M = map(int,input().split())
if N == 1:
    print("0")
    exit()
A = list(map(int,input().split()))
A.sort(reverse=True)
# print(A)
for i in range(M):
    a = A[0]//2
    A.pop(0)
    for i in range(M):
        if A[i] >= a and A[i+1] <= a :
            A.insert(i+1,a)
            break
    # print(A)
print(sum(A))

Submission status: Runtime Error

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

  a_array[np.argmax(a_array)] = a_array[np.argmax(a_array)]//2
   
print(np.sum(a_array))

Submission status: Runtime Error

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

def merge_sort(arr):
    if len(arr) <= 1:
        return arr

    mid = len(arr) // 2
    # ここで分割を行う
    left = arr[:mid]
    right = arr[mid:]

    # 再帰的に分割を行う
    left = merge_sort(left)
    right = merge_sort(right)

    # returnが返ってきたら、結合を行い、結合したものを次に渡す
    return merge(left, right)


def merge(left, right):
    merged = []
    l_i, r_i = 0, 0

    # ソート済み配列をマージするため、それぞれ左から見ていくだけで良い
    while l_i < len(left) and r_i < len(right):
        # ここで=をつけることで安定性を保っている
        if left[l_i] <= right[r_i]:
            merged.append(left[l_i])
            l_i += 1
        else:
            merged.append(right[r_i])
            r_i += 1

    # 上のwhile文のどちらかがFalseになった場合終了するため、あまりをextendする
    if l_i < len(left):
        merged.extend(left[l_i:])
    if r_i < len(right):
        merged.extend(right[r_i:])
    return merged

N,M=map(int,input().split())
A=list(map(int, input().split()))
merge_sort(A)
for i in range(M):
  A[N]=A[N]/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: Runtime Error

Solution code:
import math
n, m = map(int, input().split())
a = sorted(map(int, input().split()), reverse=True)
i = 1
while m > 0:
	if m>=i:
		m -= i
		a[0:i] = [num//2 for num in a[0:i]]
		while i>0 and a[i-1] == 0:
			del a[i-1]
			i -= 1
		if i == 0:
			break
		j = 0
		while i+j < n-1 and a[0]<a[i+j]:
			j += 1
		if j!=0:
			temp = a[i:i+j]
			a[j:i+j] = a[0:i]
			a[0:j] = temp
			i += 1
			
	else:
		a[0:m] = [num//2 for num in a[0:m]]
		m=0
if len(a)>0:
	print(sum(a))
else:
	print(0)

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
A = sorted(list(map(int, input().split())), reverse=True)
top, bottom = 0, M-1

if len(A) == 1:
    for _ in range(M):
        A[0] //= 2
else:
    for _ in range(M):
        A[top] //= 2
        if A[top] >= A[bottom]:
            if bottom >= top >= 0:
                bottom -= 1
            continue
        else:
            top += 1
print(sum(A))

Submission status: Runtime Error

Solution code:
n, m = map(int, input().split())
inl = map(int, input().split())
for i in range(m):
  mx = 0
  th = 0
  for j in range(n):
    if inl[j] > mx:
      mx = inl[j]
      th = j
  inl[j] = int(inl[j]/2)
sum = 0
for k in range(n):
  sum += inl[k]
print(sum)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
# from collections import deque
import bisect

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

ans = 0
ans += sum(A_list[0:N - M])
del(A_list[0:N - M])
for i in range(M):
    max_price = A_list.pop()
    bisect.insort(A_list, max_price // 2)
    ans += A_list[0]
    del(A_list[0])
    

ans += sum(A_list)
print(ans)

Submission status: Runtime Error

Solution code:
class Heap:
    
    def maintain_heapify(self,A,i):
        l=2*i+1
        r=2*i+2
        if self.name=='max':
            if l<len(A) and A[l]>A[i]:
                largest=l
            else:
                largest=i
            
            if r<len(A) and A[r]>A[largest]:
                largest=r
            
            if largest!=i:
                A[largest],A[i]=A[i],A[largest]
                self.maintain_heapify(A,largest)

        elif self.name=='min':
            if l<len(A) and A[l]<A[i]:
                smallest=l
            else:
                smallest=i
            if r<len(A) and A[r]<A[smallest]:
                smallest=r
            if smallest!=i:
                A[smallest],A[i]=A[i],A[smallest]
                self.maintain_heapify(A,smallest)

    def build_heap(self,A):
        i=len(A)//2
        while i>=0:
            self.maintain_heapify(A,i)
            i-=1

    def __init__(self,A,name='max'):
        self.name=name
        self.build_heap(A)
        self.heap=A

    def insert(self,v):
        self.heap.append(v)
        self.build_heap(self.heap)

    def deleteroot(self):
        root=self.heap[:1]
        tmp=self.heap[1:len(self.heap)-1]
        self.heap=self.heap[len(self.heap)-1:]+tmp
        self.build_heap(self.heap)
        return root[0]

    def get_root(self):
        return self.heap[0]
    def get_sum(self):
      	for i in range(len(self.heap)):
          self.heap[i] = int(self.heap[i])
        return sum(self.heap)


def main():
    N,M = map(int,input().split())
    A = list(map(int,input().split()))
    heap = Heap(A)
    tmp = 0
    for cnt in range(M):
        first = heap.deleteroot()
        plus = first / 2
        heap.insert(plus)
    print(heap.get_sum())
    return
main()

Submission status: Runtime Error

Solution code:
from collections import deque
import bisect

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

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

Submission status: Runtime Error

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

from collections import deque
queue=deque(A)
for i in range(M):
    queue.extend([max(queue)//2])
    A.remove(max(queue))
print(sum(queue))

Submission status: Runtime Error

Solution code:
import math
import numpy as np
N, M = map(int, input().split())
AA = [int(a) for a  in input().split()]

A_np = np.array(AA)

# print(A_np)
for x in range(M):
    A_np[A_np.argmax()] = A_np[A_np.argmax()]/2

goukei = 0

# print(A_np)

for Ai in A_np:
#     print("Ai: ",Ai)
    goukei += math.floor(Ai)
#     print(Ai, math.floor(Ai))

print(goukei

Submission status: Runtime Error

Solution code:
import numpy as np

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

A = np.sort(A)[::-1]
a = []
for i in range(0,M):
    a.append(A[i])

an = np.array(a)

for i in range(0,M):
    tmp = np.argmax(an)
    ma = an[tmp]
    an[tmp] = ma // 2

for i in range(0,M):
    A[i] = an[i]

lis = A.tolist()
print (sum(lis))

Submission status: Runtime Error

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

for i in range(m):
  mx = max(alst)
  idx = alst.index(mx)
  alst[idx] = alst[idx]/2.0
#print(alst)
for j in range(m):
  alst[j] = math.floor(alst[j])
#print(alst)

print(sum(alst))

Submission status: Runtime Error

Solution code:
import bisect

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

price.sort()

if m < n:
    add = sum(price[:n-m])
    price = price[n-m:]
else:
    add = 0

while m:
    p = price.pop() >> 1
    if len(price) < m:
        price.insert(bisect.bisect(price, p), p)
    elif len(price) == 0 and price[0] >= p:
        add += p
    else:
        price.insert(bisect.bisect(price, p), p)
    m -= 1
print(sum(price)+add)
n = int(input())
s = str(input())

Submission status: Runtime Error

Solution code:

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

i = 0
j = 0

for m in range(M):
    
    if j >= N-1:
        j = 0
        
    if A[j] < A[i + 1]:
        i +=1
        A[i] //= 2
        j = 0
    else:
        A[j] //= 2
        j += 1
        
    
        
print(sum(A))

Submission status: Runtime Error

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

A.sort(reverse=True)
List = [[] for i in range(100)]
for i in range(N):
    temp = bin(A[i])
    List[len(temp)-3].append(A[i])

List.reverse()
List = [i for i in List if i != []]
for i in range(len(List)):
    List[i].sort(reverse=True)
c = 0
cnt = 0
while cnt < M:
    for i in range(cnt+1):
        for j in range(len(List[i])):
            List[i][j] = List[i][j]//2
            c += 1
            if c == M:
                cnt = M+1
                c = M+1
                break
        if c > M:
            break
    cnt += 1
            
ans = 0
for i in range(len(List)):
    ans += sum(List[i])
            
print(ans)

Submission status: Runtime Error

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

n,m = map(int,input().split())
a = list(map(int,input().split()))
a.sort(reverse=True)
j = 0
for i in range(m):
  a[j] //= 2
  if a[0] > a[j]:
    j = 0
    a.sort(reverse=True)
  elif a[j] < a[j+1]:
    j += 1
print(sum(a))

Submission status: Runtime Error

Solution code:
master = list(map(int, input().split()))
merchandises = list(map(int, input().split()))

if (len(merchandises) == 1):
    merchandises.append(0)
else:
    merchandises.sort(reverse = True)

tmp = 0
dcnum = 0
for dc in range(master[1]):
    if (dcnum > 0):
        break
    dcnum = int(merchandises[0] / merchandises[1])
    tmp = int(merchandises[0] / 2 * dcnum)
    dcnum -= 1
    merchandises[0] = tmp
    idx = 1
    exchange = False
    while(tmp < merchandises[idx]):
        merchandises[idx - 1] = merchandises[idx]
        idx += 1
        exchange = True
        if (idx == master[0]):
            break
    if (exchange):
        merchandises[idx - 1] = tmp

fullPrice = 0
for p in merchandises:
    fullPrice += p

print(fullPrice)

Submission status: Runtime Error

Solution code:
import sys
import math
import numpy as np
from fractions import gcd
# import queue
# from collections import Counter
# from itertools import accumulate
# from functools import reduce

def lcm(a, b):
    return a * b // gcd(a, b)

def combination_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

big_prime = 1000000007

"""
# 標準入力取得
## 文字列
 =  sys.stdin.readline().rstrip()
 =  list(sys.stdin.readline().rstrip())

## 数値
 =  int(sys.stdin.readline())
 =  map(int, sys.stdin.readline().split())
 =  list(map(int, sys.stdin.readline().split()))
 =  [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
"""

N,M = map(int, sys.stdin.readline().split())
list_A = list(map(int, sys.stdin.readline().split()))
list_A.sort(reverse=True)

list_A_np = np.array(list_A)

for i in range(M):
    # list_A.sort(reverse=True)
    # idx_max = list_A.index(max(list_A))
    # list_A[idx_max] = int(list_A[idx_max]/2)

    # if(list_A[0] > list_A[1]):
    #     list_A[0] = int(list_A[0]/2)
    # else:
    #     list_A.sort(reverse=True)
    #     list_A[0] = int(list_A[0]/2)


    if(list_A_np[0] > list_A_np[1]):
        list_A_np[0] = int(list_A_np[0]/2)
    else:
        # idx_max = list_A_np.argmax()
        # list_A_np[idx_max] = int(list_A_np[idx_max]/2)
        list_A_np = np.sort(list_A_np)[::-1]
        list_A_np[0] = int(list_A_np[0]/2)

    # idx_max = list_A_np.argmax()
    # list_A_np[idx_max] = int(list_A_np[idx_max]/2)

ans = 0

for i in range(N):
    # ans += list_A[i]
    ans += list_A_np[i]

print(ans)

Submission status: Runtime Error

Solution code:
import bisect

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

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

for w in range(M):
    max2=A.pop(N-1)/2
    #A[N-1]=A[N-1]/2
    #max=A[N-1]
    if max2<A[N-2]:
        bisect.insort_left(A,max2)
    else:
        A[N-1]=max2
    #print(A)

B=list(map(int, A))
#print(B)
print(sum(B))

Submission status: Runtime Error

Solution code:
import numpy as np

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

if N == 1:
    for i in range(M):
        a //= 2
    print(a[0])
    exit()

a.sort()
cur = M - 1
for i in range(M):
    if i == 0:
        a[-1] //= 2
    else:
        if (a[cur-1] > a[cur]):
            cur -= 1
            a[a[cur:].argmax()+cur] //= 2
        else:
            if cur == M-1:
                a[-1] //= 2
            else:
                a[a[cur:].argmax()+cur] //= 2
print(sum(a))

Submission status: Runtime Error

Solution code:
import bisect
import copy

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

for _ in range(M):
  tmp_a = int(A2[-1]/2)
  if A2[-2] <= tmp_a:
    A2[-1] = tmp_a
  else:
    del A2[-1]
    A2.insert(bisect.bisect_left(A2,tmp_a),tmp_a)
print(sum(A[:N-M])+sum(A2))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
print(sum(a))

Submission status: Runtime Error

Solution code:
n, m = map(int, input().split())
a = [int(i) for i in input().split()]
a.sort(reverse=True)
if n == 1:
	print(a[0]//(2**m))
else:
	for s in range(m):
		maxnum = 0
		flag = 0
		for t in range(s):
			if maxnum <= a[t]:
				maxnum = a[t]
				flag = t
		a[flag] = a[flag]//2
	print(sum(a))

Submission status: Runtime Error

Solution code:
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
A = sorted(A, reverse=True)
cnt = 0
while True:
    A[0] = A[0] // 2
    cnt += 1
    A = sorted(A, reverse=True)
    print(A)
    if cnt == M:
        break

print(sum(A))

Submission status: Runtime Error

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[-1]//2
  if t<a[-2]:
    bisect.insort(a,t)
    del a[-1]
  else:
    continue

print(sum(a))

Submission status: Runtime Error

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


while M > 0:
  A.sort(reverse = True)
  x = 0
  while A[0] >= A[1]:
    A[0] /= 2
    x += 1
  M -= x

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

Submission status: Runtime Error

Solution code:
from bisect import bisect_left
import sys

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

if N == 1:
    for i in range(M):
        A[0] = A[0] // 2
    print(sum(A))
    sys.exit()

A.sort(reverse=True)

index = 0
for i in range(M):
    A[index] = A[index] // 2
    aMax = A[index]
    for j in range(N):
        if aMax < A[i]:
            aMax = A[i]
            index = i
            break

print(sum(A))

Submission status: Runtime Error

Solution code:
import numpy as np
N, M = map(int, input().split())
items = np.array(list(map(int, input().split())))
amari = (M-10)%2
if M > 10:
    for i in range((M-10)/2):
        items[items.argmax()]/=4
    for i in range(10+amari):
        items[items.argmax()]/=2
else:
	for i in range(M):
        items[items.argmax()]/=2
print(round(np.sum(items)))

Submission status: Runtime Error

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

A.sort(reverse=True)
A.append(0)
i=0

while M>0:
    ss=1
    while ss==1:
        if A[i]>A[i+1] and M>i:
            for j in range(i+1):
                A[j]=A[j]//2
                M-=1
        elif A[i]>A[i+1]:
            for j in range(M):
                A[j]=A[j]//2
                M-=1
            ss=0
        else:
            ss=0
    if M>0:
        for j in range(i,-1,-1):
            if A[j]<A[j+1]:
                tmp=A[j]
                A[j]=A[j+1]
                A[j+1]=tmp
            else:
                break
    
    if A[0]==0 or i==N:
        M=0

    i+=1

print(sum(A))

Submission status: Runtime Error

Solution code:
import math
import numpy as np

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


for i in range(m):
    tem = ar.argmax()
    ar[tem] = math.floor(ar[tem]/2)

print(ar.sum())

Submission status: Runtime Error

Solution code:
# 2より大きい値段のものに高いものから順に割引券を振り分けていく
n,m = list(map(int, input().split()))
a = list(map(int, input().split()))
a = sorted(a, key=lambda x: -x)
coupon = [0 for i in range(n)]

v = 0
for i in range(n):
    if a[i] > 2:
        v += 1

i = 0
while m > 0 and v > 0:
    if len(a) == 1:
        coupon[i] = m
        break
    if a[i] > 2:
        l = a[i] // 2**(coupon[i]+1)
        if l >= 0:
            coupon[i] += 1
            if l == 0:
                v -= 1
        m -= 1
        i += 1
    elif a[i] <= 2 and m > 0:
        i = 0

total = 0
for i in range(n):
    if a[i] < 3 and m > 0:
      total += a[i] // 2
      m -= 1
    else:
      total += a[i] // 2**coupon[i]

print(total)

Submission status: Runtime Error

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

  a_array[np.argmax(a_array)] = a_array[np.argmax(a_array)]//2
   
print(np.sum(a_array))

Submission status: Runtime Error

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

a.sort(reverse = True)
count = m
for i in range(m-1):
    while count > math.floor(m/2) or a[i] > a[i+1]:
        a[i] = a[i]/2
        count = count - 1
    if count > 0:
        a[i+1] = a[i+1]/2
        count = count - 1
print(round(sum(a)))

Submission status: Runtime Error

Solution code:
import math
n,m=map(int, input().split())
a=sorted(list(map(int, input().split())),reverse=True)
tot=0
rate=[0]*n
p=[0]*n

for i in range(n-1):
  rate[i]=math.log2(a[i]/a[i+1])
  
cur=0
while m>0:
  if rate[cur]>0:
    p[cur]+=1
    rate[cur]-=1
    m-=1
    if cur>0:
      rate[cur-1]+=1
      cur-=1
  else:
    cur+=1
  
for i in range(n):
  tot+=int(a[i]/(2**p[i]))
print(tot)

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
A = sorted(list(map(int, input().split())), reverse=True)
top, bottom = 0, M-1

if len(A) == 1:
    for _ in range(M):
        A[0] //= 2
else:
    for _ in range(M):
        A[top] //= 2
        if A[top] >= A[bottom]:
            bottom -= 1
            continue
        else:
            top += 1
print(sum(A))

Submission status: Runtime Error

Solution code:
import numpy as np
import math
N,M = [int(x) for x in input().split(" ")]
a = np.array([int(x) for x in input().split(" ")])
alog = np.log2(a)
sorted_args = np.argsort(alog)
sorted_args = N-sorted_args - 1
sorted_alog = np.sort(alog)[::-1]
sorted_Ms = [0 for _ in range(N)]
next_start_idx = 0
for m_idx in range(M):
    for idx in range(next_start_idx,len(sorted_alog) - 1):
        if sorted_alog[idx + 1] <= sorted_alog[idx]:
            next_start_idx = max(0,idx - 1)
            break
        idx += 1
    sorted_alog[idx] -= 1
    sorted_Ms[idx] += 1
Ms = [0 for _ in range(N)]
for order, m_count in enumerate(sorted_Ms):
    for idx, this_order in enumerate(sorted_args):
        if order == this_order:
            Ms[idx] = m_count
res = 0
for i, price in enumerate(a):
    res += math.floor(price / (2 ** Ms[i]))
print(res)

Submission status: Runtime Error

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

A = sorted(A)[::-1]
a = 0
for i in range(M):
    A[a] = A[a] // 2
    if a > 0:
        if A[a-1] > A[a]:
            a -= 1
    if a+1 <= len(A)-1:
        if A[a] < A[a+1]:
            a += 1
            if A[a] < A[a+1]:
                a += 1
        if a+2 <= len(A)-1:
            if A[a] in [A[a], A[a]+1]:
                if A[a] < A[a+2]:
                    a += 2

print(sum(A))

Submission status: Runtime Error

Solution code:
from math import floor
n,m=map(int,input().split())
a=list(map(int,input().split()))
a.sort(reverse=True)
while m>0:
  a[0]/=2
  m-=1
  if a[0]<a[1]:
    a.sort(reverse=True)
for i in range(n):
  a[i]=floor(a[i])
print(sum(a))

Submission status: Runtime Error

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

A.sort(reverse=True)
List = [[] for i in range(100)]
for i in range(M):
    temp = bin(A[i])
    List[len(temp)-3].append(A[i])

List.reverse()
List = [i for i in List if i != []]
for i in range(len(List)):
    List[i].sort(reverse=True)
c = 0
cnt = 0
while cnt < M:
    for i in range(cnt+1):
        for j in range(len(List[i])):
            List[i][j] = List[i][j]//2
            c += 1
            if c == M:
                c = M+1
                break
        if c > M:
            break
    cnt += 1
            
ans = 0
for i in range(len(List)):
    ans += sum(List[i])
            
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np

s = input().split()
N = int(s[0])
M = int(s[1])
A = np.array(list(map(int, input().split())))
# A = list(map(int, input().split()))

for i in range(M):
    # j = A.index(max(A))
    # j = A.argmax()
    A[A.argmax()] //= 2
    # A.sort()
    # A[N-1] //= 2

print(np.sum(A))

Submission status: Runtime Error

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

for i in range(m):
  if(A[0]<A[1]):
    A.sort(reverse=True)
  A[0]=A[0]//2
  
print(sum(A))

Submission status: Runtime Error

Solution code:
import math
import sys

class Solution(object):
    def __init__(self):
        pass
        
    def Sol(self, n, m, a):
        a.sort()  

        return self.Best(n, m, a, {}) 

    def Best(self, idx, m, a, tb):
        if idx == 0:
            return 0

        if (idx, m) in tb:
            return tb[(idx, m)]

        sl = 2 ** 60 
        for i in range(0, m + 1):
            sl = min(sl, int(math.floor(a[idx - 1] / 2 ** i)) + self.Best(idx - 1, m - i, a, tb))
            if a[idx - 1] < 2 ** i:
                break
        tb[(idx, m)] = sl
        return sl


def main():
    sys.setrecursionlimit(100001)
    info = [int(e) for e in input().split()]
    a = [int(e) for e in input().split()]
    print(Solution().Sol(info[0], info[1], a)) 
    return 0

if __name__ == "__main__":
    main()