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:



def main():


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

    if N <= 3:
        for _ in range(M):
            priceList[0] //= 2
            priceList.sort()
        print(sum(priceList))
        exit()

    atMax = 1
    
    for _ in range(M):
        if atMax-1 < 0: atMax = 1
        
        if priceList[atMax-1] > priceList[atMax+1]:
            if priceList[atMax-1] >priceList[atMax]:
                priceList[atMax-1] //= 2
                M -=1
                atMax = atMax-1
            else:
                priceList[atMax] //= 2
                M -=1
        else: 
            if priceList[atMax+1] > priceList[atMax]:
                priceList[atMax+1] //=2
                M -=1
                atMax = atMax+1
            else:
                priceList[atMax] //= 2
                M -= 1
    print(sum(priceList))











if __name__ == "__main__":
    main()

Submission status: Runtime Error

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

A_i.sort(reverse=True)
for i in range(M):
    if A_i[0] >= A_i[1]:
        A_i[0] = A_i[0]//2
    else:
        A_i.sort(reverse=True)
        A_i[0] = A_i[0]//2
total = sum(A_i)
print(total)

Submission status: Runtime Error

Solution code:
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()

    left = 0
    right = n-2
    mid = 0
    while left < right:
        mid = (left + right) // 2
        if a[mid] > temp:
            right = mid - 1
            if right == left:
                a.insert(right+1, temp)
        elif a[mid] < temp:
            left = mid + 1
            if right == left:
                a.insert(right, temp)
        else:
            a.insert(right, temp)
            break
    
    
print(sum(a))

Submission status: Runtime Error

Solution code:
import sys
import numpy as np
input = sys.stdin.readline

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


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

print(sum(A))

Submission status: Runtime Error

Solution code:
n,m=map(int,input().split())
a=sorted(map(int,input().split()),reverse=True)
cnt=0
i=0
for _ in range(m):
    if i==len(a): i=0
    a[i]//=2
    if a[i]<a[i+1]: i+=1
print(sum(a))

Submission status: Runtime Error

Solution code:
get1 = list(map(int, input().split()))
get2 = list(map(int, input().split()))
 
N = get1[0]
M = get1[1]
 
get2.sort()
 
for i in range(M):
 
  get2[N -1] = get2[N -1] // 2
  get2.sort()
  
print(num(get2))

Submission status: Runtime Error

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
    if a[0] < a[1]:
        a.sort(reverse = True)

print(sum(a))

Submission status: Runtime Error

Solution code:
mnum, gnum = map(int, input().split())
array = list(map(int, input().split())

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

print(sum(array))

Submission status: Runtime Error

Solution code:
from bisect import bisect
n,m=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
def calc(a,m):
    if m==0:
        return sum(a)
    else:
        tmp = a.pop()>>1
        if tmp >0:
            tmp_index = bisect(a,tmp)
            a.insert(tmp_index,tmp)
        elif a==[]:
            return 0
        return calc(a,m-1)
print(calc(a,m))

Submission status: Runtime Error

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

for i in range(m):
    max = 0
    for j in range(n):
        if max < a[j]:
            max = a[j]
            max_i = j
    a[max_i] = math.floor(a[max_i] / 2)
###    a[a.index(max(a))] = math.floor(a[a.index(max(a))] / 2)

print(sum(a))

Submission status: Runtime Error

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


def waru(i, tempb):
    if a[i] >= 1:
        a[i - 1] = a[i]
        a[i] = tempb

        if a[i] < a[i + 1]:
            waru(i + 1, tempb)


while m > 0:
    a[0] = a[0] // 2
    if a[0] < a[1]:
        waru(1, a[0])
    if a[0] < 1:
        break
    m -= 1

if a[0] < 1:
    print(0)
else:
    print(sum(a))

Submission status: Runtime Error

Solution code:
s = input().split()
n = int(s[0])
m = int(s[1])
a_i = input().split()
a_i = [int(i) for i in a_i]
a_i.sort(reverse=True)
cnt = 1
while(cnt < m):
  discount = int(a_i[0] / 2)
  while(discount > a_i[1]):
    discount = int(discount / 2)
    cnt += 1
  a_i[0] = discount
  cnt += 1
  a_i.sort(reverse=True)
print(sum(a_i))

Submission status: Runtime Error

Solution code:
import numpy as np
import sys
input = sys.stdin.readline


def insertion_sort(array):
    n = len(array)
    for i in range(1, n):
        tmp = array[i]  # 挿入する値を退避
        if tmp < array[i-1]:
            # 挿入する位置までずらしていく
            j = i
            while True:
                array[j] = array[j-1]
                j -= 1
                if j == 0 or tmp >= array[j-1]:
                    break
            array[j] = tmp  # 空いた位置に退避していた値を挿入


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

    for _ in range(M):
        A[0] >>= 1
        if A[0] < A[1]:
            insertion_sort(A)

    print(sum(A))


if __name__ == "__main__":
    main()

Submission status: Runtime Error

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

a.sort(reverse=True)

while m > 0:
  while a[0] >= a[1]:
    if m == 0:
      break
    a[0] = a[0] // 2
    m -= 1
      
  a[0], a[1] = a[1], a[0]

print(sum(a))

Submission status: Runtime Error

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

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

def waribiki(X,Y):
    return X//(2**Y)

A.sort(reverse=True)
while M>0:
    A[0] = waribiki(A[0],1)
    M -= 1
    if len(A)>1:
        if A[0] < A[1]:
            i=0
            while A[i] < A[i+1]:
                tmp = A[i+1]
                A[i+1]=A[i]
                A[i]=tmp
                i+=1

print(sum(A))

Submission status: Runtime Error

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

while m>=1 and a[0] >= a[1]:
  a[0] //= 2
  m -= 1

a = sorted(a)[::-1]

while m>=1:
  a[0] //= 2
  a = sorted(a)[::-1]
  m -= 1

print(sum(a))

Submission status: Runtime Error

Solution code:
get1 = list(map(int, input().split()))
get2 = list(map(int, input().split()))

N = get1[0]
M = get1[1]

get2.sort()

for i range(M):

  get2[len(get2) -1] = get2[len(get2) -1] // 2
  get2.sort()
  
print(num(get2))

Submission status: Runtime Error

Solution code:
import numpy as np
N, M = list(map(int, input().split(' ')))
x = np.sort(np.array(list(map(int, input().split(' ')))))[::-1]
i = 0
while M > 0:
    if x[i] >= x[i+1]:
        x[i] = np.trunc(x[i]/2.0)
    else:
        i += 1
    M -= 1
print(np.sum(x))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import bisect 
n,m = map(int,input().split())
a = sorted(list(map(int,input().split())))
 
for i in range(m):
  b = a[-1]
  a.remove(b)
  b = int(b/2)
  for j in range(99*99):
    if b >= a[-1]:
      b = int(b/2)
    else:
      break
  bisect.insort(a,b)
  
print(sum(a))

Submission status: Runtime Error

Solution code:
n, m = [int(x) for x in input().split()]
a = sorted([int(x) for x in input().split()], reverse=True)
i = 0
j = 1
l = len(a)
for _ in range(m):
    if n == 1:
        a[0] //=2
    else:
        if a[0] >= a[i] and a[0] >= a[j]:
            a[0] //= 2
        elif a[i] >= a[j]:
            a[i] //= 2
        else:
            a[j] //= 2
        if a[j] < a[j+1]:
            i = j
            j = j+1
print(sum(a))

Submission status: Runtime Error

Solution code:
import collections
n, k, q = map(int, input().split())
A = [int(input()) for _ in range(q)]
a_c = collections.Counter(A)
cnt = 0
x = ['No'] * n
if q-k < 0:
	for a in range(n):
		print('Yes')
	exit()
for i,j in a_c.items():
  if j > q-k:
    x[i-1] = 'Yes'
for k in x:
	print(k)

Submission status: Runtime Error

Solution code:
import math

n, m = map(int, input().split())
a = list(map(int, input().split()))
a.append(0)
a.sort(reverse=True)


def waru(i, tempb):
    if a[i] >= 1:
        a[i - 1] = a[i]
        a[i] = tempb

        if a[i] < a[i + 1]:
            waru(i + 1, tempb)


while m > 0:
    a[0] = a[0] // 2
    if a[0] < a[1]:
        waru(1, a[0])
    if a[0] < 1:
        break
    m -= 1

if a[0] < 1:
    print(0)
else:
    print(sum(a))

Submission status: Runtime Error

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

A.sort(reverse=True)
for i in range(M):
	for j in range(N):
		if A[j] >= A[j+1]:
			break
		else:
			A[j], A[j+1] = A[j+1], A[j]
	A[0] = A[0]//2
print(sum(A))

Submission status: Runtime Error

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

sorted_A = list(reversed(sorted(A)))

money = 0

for a in sorted_A:
    if M > 2:
        used = round(M/2)
    elif M != 0:
        used = 1
    else:
        used = 0

    if int(math.log(a)) > used:
        used = int(math.log(a))

    money += a // 2**(used)
    M = M - used

print(money)

Submission status: Runtime Error

Solution code:
# coding: utf-8
N, M = [int(x) for x in input().split(" ")]
As = [int(x) for x in input().split(" ")]
As.sort()
for i in range(M):
    As[-1] //= 2
    if As[-1] < As[-2]:
        As.sort()
sum = 0
for num in As:
    sum += num
print(sum)

Submission status: Runtime Error

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

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

print(sum(A))

Submission status: Runtime Error

Solution code:
n1, n2 = [int(i) for i in input().split()]
n3 = [int(i) for i in input().split()]

n3.sort(reverse = True)

c1 = 0
while True:
    n3[0] = n3[0] // 2
    c1 += 1
    if c1 >= n2:
        break
    t2 = 1
    while len(n3) != 1:
        if n3[t2] >= n3[0]:
            n3[t2] = n3[t2] // 2
            t2 += 1
            c1 += 1
            if c1 >= n2:
                break
        else:
            break

    if c1 >= n2:
        break

    n3.sort(reverse = True)


r1 = 0
for i2 in range(n1):
    r1 += n3[i2]

print(r1)

Submission status: Runtime Error

Solution code:
n,m=map(int,input().split())
a=list(map(int,input().split()))
A = sorted(a,reverse=True)
ct=0
j=0
for i in range(m):
    if A[j]>A[j+1] and j==0:
        A[j]=int(A[j]/2)
        ct+=1
        j+=1
    elif A[j]>A[j+1] and j>0 and not A[j]<A[j-1]:
        A[j]=int(A[j]/2)
        ct+=1
        j+=1
    elif j>0 and A[j]<A[j-1]:
        A[j]=int(A[j]/2)
        ct+=1
        j-=1
    else:
        j+=1
print(sum(A))

Submission status: Runtime Error

Solution code:
import sys, bisect

def main():
    _,M,*A = map(int, open(0).read().split())

    A.sort()
    i = M
    while i > 0:
        a = int(A.pop() / 2)
        i-=1
        while a >= A[-1] and i > 0:
            a = int(a / 2)
            i-=1
        bisect.insort_left(A,a)

    print(sum(A))

if __name__=='__main__':
    main()

Submission status: Runtime Error

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

list.sort(A, reverse=True)
print(A)
for m in range(M):
    tmp = int(A[0] / 2)
    del A[0]
    for i in range(len(A)):
        if A[i] < tmp:
            A.insert(i, tmp)
            break

print(sum(A))

Submission status: Runtime Error

Solution code:
n,m=map(int,input().split())
A=[float(x) for x in input().split()]
sum=0
A.sort
for i in range(m):
    A[m-1]=A[m-1]/2
    v=A[m-1]
    j=m-2
    while j>=0 and A[j]>v:
        A[j+1]=A[j]
        j-=1
    A[j+1]=v

#A_int=[int(x) for x in A]
#print(sum(A_int))
for x in A:
    sum+=int(x)

print(sum)

Submission status: Runtime Error

Solution code:
import math

n, m = map(int, input().split())
item_price = list(map(int, input().split()))
# n, m = (3, 7)
# item_price = [1, 1, 1]
item_price.sort(reverse=True)
devided_two_price = [math.ceil(math.log2(i)) for i in item_price]
use_ticket_list = [0] * n
sum = 0

x = 0
a = 2
for i in range(m):
    if devided_two_price[x] == a:
        x += 1
        use_ticket_list[x] += 1
        devided_two_price[x] -= 1
    elif devided_two_price[x] >= devided_two_price[x+1]:
        use_ticket_list[x] += 1
        devided_two_price[x] -= 1
    else:
        x += 1
        use_ticket_list[x] += 1
        devided_two_price[x] -= 1
    if x == n-1:
        x = 0
        a -= 1

for i in range(n):
    sum += item_price[i] // (2**use_ticket_list[i])

print(sum)

Submission status: Runtime Error

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


#import scipy.optimize
import math

    
##################################################################

if __name__ == "__main__":

    Input = [input() for i in range(2)]
    N,M = list(map(int,Input[0].split()))
    A = list(map(int,Input[1].split()))
    A.sort(reverse=True)

    if N==1:
        Money = math.floor(A[0]/(2**M))
        print(Money)
    else:      
        Use = 0
        while Use < M:
            if A[0] == A[1]:
                Usenow = 1
                Use += Usenow
            else:
                Usenow = math.ceil(math.log2(A[0])-math.log2(A[1]))
                Use += Usenow
                if Use > M:
                    Usenow -= Use - M
                    Use = M
            temp = math.floor(A[0]/(2**Usenow))
            for i in range(1,N):
                if temp < A[i]:
                    A[0:i] = A[1:i+1]
                    A[i] = temp
                    break
                else:
                    continue
        print(sum(A))

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(100002)
input=sys.stdin.readline
n,m=map(int,input().split())
a=list(map(int,input().split()))
for i in range(m):
    max(a)//=2
print(sum(a))

Submission status: Runtime Error

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

A = input().split()

B = [0]*N
C = [0]*N

for _ in range(M):
    i = 0
    for _ in A:
        D = int(int(A[int(i)])/2))
        B[int(i)] = (int(A[int(i)]) - D
        C[int(i)] = D
        i += 1
    num = B.index(max(B))
    A[num] = C[num]

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

print(result)

Submission status: Runtime Error

Solution code:
from math import log2, floor
n, m = map(int, input().split())
lst = [int(i) for i in input().split()]
lst.sort()
if n == 1:
    lst[0] //= 2 ** m
else:
    while m:
        x = floor(log2(lst[-1] / lst[-2]))
        lst[-1] //= x
        m -= x
        lst.sort()
print(sum(lst))

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

A.sort(reverse=True)
for i in range(M):
	for j in range(M-i):
		if A[j] >= A[j+1]:
			break
		else:
			A[j], A[j+1] = A[j+1], A[j]
	A[0] = A[0]//2
print(sum(A))

Submission status: Runtime Error

Solution code:
import bisect
from collections import deque
N, M = map(int, input().split())
B = [int(x) for x in input().split()]
B = sorted(B)
A = deque([])
for i in range(N):
    A.append(B[i])
# print(A)
for i in range(M):
    value = A.pop()
    value = value//2
    bisect.insort_left(A, value)
# print(A)
ans = sum(A)
print(ans)

Submission status: Runtime Error

Solution code:
# ABC141
def main():
    N, M, *A = map(int, open(0).read().split())
    if N == 1:
        ans = A[0] >> M
        print(ans)
        return
    A.sort(reverse=1)
    A += [0, 0]
    cur, prev = 0, 0
    for _ in range(M):
        x, y = A[cur] >> 1, A[cur + 1] >> 1
        if x > y:
            A[cur] = x
        else:
            A[cur + 1] = y
        if A[cur + 2] >= A[cur]:
            cur += 1
    ans = sum(A)
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
import sys
import math
# import numpy
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)

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)

ans = 0

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

print(ans)

Submission status: Runtime Error

Solution code:
n,m=map(int,input().split())
a=list(map(int,input().split()))
A = sorted(a,reverse=True)
ct=0
j=0
for i in range(m):
    if A[j]<A[j+1] and j==0:
        A[j]=int(A[j]/2)
        ct+=1
        j+=1
    elif A[j]<A[j+1] and j>0 and not A[j]>A[j-1]:
        A[j]=int(A[j]/2)
        ct+=1
        j+=1
    elif j>0 and A[j]<A[j-1]:
        A[j]=int(A[j]/2)
        ct+=1
        j-=1
    else:
        j+=1
print(sum(A))

Submission status: Runtime Error

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

N, M = map(int,input().split())
A = list(map(int,input().split()))
sort_A = sorted(A, reverse=True)
L = []
for i in range(N):
  L.append(len(bin(sort_A[i])))

count_discount = [0]*M
for i in range(M):
  index = L.index(max(L))
  L[index] = L[index] -1
  count_discount[index] += 1

sum = 0
for i in range(N):
  if count_discount[i] >= 1:
    q, mod = divmod(sort_A[i], (2*count_discount[i]))
    sum += q
  else:
    sum += sort_A[i]
print(sum)

Submission status: Runtime Error

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] = int(A[0] / 2)
    if A[0] < A[1]:
        A.sort(reverse=True)

print(sum(A))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n, m = map(int, input().split())
li = list(map(int, input().split()))
for i in range(m):
    li.sort()
    li[-1] = li[-1] // 2
    if len(li) > 2:
        if li[-2] < li[-1] and i < range(m):
            li[-1] = li[-1] // 2
            i = +1
        if li[-2] < li[-1] and i < range(m):
            li[-1] = li[-1] // 2
            i = +1
        if li[-2] < li[-1] and i < range(m):
            li[-1] = li[-1] // 2
            i = +1
        if li[-2] < li[-1] and i < range(m):
            li[-1] = li[-1] // 2
            i = +1
        if li[-2] < li[-1] and i < range(m):
            li[-1] = li[-1] // 2
            i = +1
    else:
        if i < range(m):
            li[-1] = li[-1] // 2
            i = +1
        if i < range(m):
            li[-1] = li[-1] // 2
            i = +1
        if i < range(m):
            li[-1] = li[-1] // 2
            i = +1
        if i < range(m):
            li[-1] = li[-1] // 2
            i = +1
        if i < range(m):
            li[-1] = li[-1] // 2
            i = +1
print(sum(li))

Submission status: Runtime Error

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

A = [int(x) for x in input().split()]
A.sort(reverse=True)

for i in range(M):
    first = A[0]
    second = A[1]
    if(first == 0):
        break
    while(i<M):
        first = first >> 1
        i += 1
        if(first < second):
            break
    A[0] = first
    A.sort(reverse=True)

print(sum(A))

Submission status: Runtime Error

Solution code:
# ABC141
def main():
    N, M, *A = map(int, open(0).read().split())
    if N == 1:
        ans = A[0] >> M
        print(ans)
        return
    A.append(0), A.sort(reverse=1)
    cur, prev = 0, 0
    for _ in range(M):
        x, y = A[cur] >> 1, A[cur + 1] >> 1
        if x > y:
            A[cur] = x
        else:
            A[cur + 1] = y
        if A[cur + 2] >= A[cur]:
            cur += 1
    ans = sum(A)
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
num ,m =map(int,input().split())
if num == 1:
    s = int(input())
else:
    arr = sorted(list(map(int,input().split())),reverse=True)

if num == 1:
    print(s//(2**m))
    
else:
    for i in range(m):
        for j in range(len(arr)):
            if arr[j]//2 < arr[j+1]:
                arr[j] = arr[j] //2
                
                if arr[j] < arr[j+1]:
                    arr[j],arr[j+1] = arr[j+1],arr[j]
                break
    print(sum(arr))

Submission status: Runtime Error

Solution code:
n,m=map(int,input().split())
A=[float(x) for x in input().split()]
A.sort
for i in range(m):
    A[m-1]=A[m-1]/2
    v=A[m-1]
    j=m-2
    while j>=0 and A[j]>v:
        A[j+1]=A[j]
        j-=1
    A[j+1]=v
    

A_int=[int(x) for x in A]
print(sum(A_int))

Submission status: Runtime Error

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

for i in range(m):
  b = a[-1]
  a.remove(b)
  b = int(b/2)
  bisect.insort_left(a,b)
  
print(sum(a))

Submission status: Runtime Error

Solution code:
n, m = map(int, input().split())
a_array = list(map(int, input().split()))
a_array.sort(reverse=True)
## for x in range(n):
for x in range(m):
    ## 回数券分ループ
    for y in range(n):
        ## 品物数分ループ
        if n == 1 or a_array[y] >= max(a_array[y + 1: n]):
            ## index(y + 回数券使った回数)より大きければ半額しても良い
            a_array[y] = math.floor(a_array[y] / 2)
            break
print(int(sum(a_array)))

Submission status: Runtime Error

Solution code:
import math

n, m = map(int, input().split())
A = list(map(int, input().split()))
As = sorted(A, reverse = True)
for i in range(m):
    ii = math.floor(As[0]/2)
    As[0] = ii
    if As[0] < As[1]:
        As = sorted(As, reverse=True)


print(int(sum(As)))

Submission status: Runtime Error

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

B = [A[0]]
A.pop(0)
for i in range(M):
    print(A)
    print(B)
    if len(A) == 0 or B[0] >= A[0]:
        B[0] //= 2
    else:
        B.append(A[0] // 2)
        A.pop(0)
    B.sort(reverse=True)
    if B[0] == 0:
        break
        
ans = 0
for i in range(len(A)):
    ans += A[i]
for i in range(len(B)):
    ans += B[i]
print(ans)

Submission status: Runtime Error

Solution code:
n,m=map(int,input().split())
a=list(map(int,input().split()))
A = sorted(a,reverse=True)
ct=0
j=0
for i in range(m):
    A[j]=int(A[j]/2)
    ct+=1
    if A[j]<A[j+1] and j==0:
        j+=1
    elif A[j]<A[j+1] and j>0 and not A[j]>A[j-1]:
        j+=1
    elif j>0 and A[j]<A[j-1]:
        j-=1
print(sum(A))

Submission status: Runtime Error

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]=int(a[0]/2)
    if a[0]<=a[1]:
        a.sort(reverse=True)
print(sum(a))

Submission status: Runtime Error

Solution code:
import sys
 
input = sys.stdin.readline
 
def main():
    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))
 
 
 
if __name__ == "__main__":
    main()
 
import sys

input = sys.stdin.readline

def main():
    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))



if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
import numpy as np

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

for i in range(int(s[1])):
    # j = A.index(max(A))
    # j = A.argmax()
    A[A.argmax()] //= 2

print(sum(A))

Submission status: Runtime Error

Solution code:
n, m = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
from collections import deque
import bisect
d = deque(A)
print(1)
for _ in range(m):
    max_ = d.pop()
    tmp = max_ // 2
    index = bisect.bisect_left(d, tmp)
    d.insert(index, tmp)
print(sum(d))

Submission status: Runtime Error

Solution code:
if __name__ == '__main__':
    import sys
    input = sys.stdin.readline

    from collections import deque


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

    aa = list(map(int, input().split()))
    aa.sort(reverse=True)
    aa = deque(aa)

    if n == 1:
        a = aa.popleft()
        for _ in range(m):
            a = a // 2
        print(a)
        exit()

    top = aa.popleft()

    deque_list = [aa, deque()]
    top_list = [deque_list[0].popleft(), top//2]


    for _ in range(m-1):
        max_num = max(top_list)
        max_index = top_list.index(max_num)
        try:
            deque_list[max_index+1].append(max_num//2)
        except IndexError:
            deque_list.append(deque())
            top_list.append(max_num//2)
        if top_list[max_index+1] == 0:
            top_list[max_index+1] = deque_list[max_index+1].popleft()
        try:
            top_list[max_index] = deque_list[max_index].popleft()
        except IndexError:
            top_list[max_index] = 0

    ans = sum(top_list)
    for one_deque in deque_list:
        ans += sum(one_deque)
    print(ans)

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
A = list(map(int, input().split()))
import math
B = [0.0 for i in range(N)]
C = [0 for i in range(N)]
for i in range(N):
  B[i] = math.ceil(math.log2(A[i]))
  
MB = max(B)

for i in range(MB):
  mb = MB-i
  for j in range(N):
    if B[j] >= mb:
      C[j] = B[j] - mb
  if sum(C) > M:
    print(Cold)
  else:
    Cold = [C[k] for k in range(N)]
    break
for i in range(N):
  A[i] = A[i] // (2**Cold[i])

M -= sum(Cold)


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

Submission status: Runtime Error

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

sum = 0
for i in range(len(a)):
     sum += int(math.floor(a[i]))
print(sum)

Submission status: Runtime Error

Solution code:
import heapq
def _heappush_max(heap, item):
    heap.append(item)
    heapq._siftdown_max(heap, 0, len(heap)-1)
def _heappop_max(heap):
    lastelt = heap.pop()    
    if heap:
        returnitem = heap[0]
        heap[0] = lastelt
        heapq._siftup_max(heap, 0)
        return returnitem
    return lastelt

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

heapq._heapify_max(price)

for i in range(M):
    a = heapq._heappop_max(price)
    a //= 2
    _heappush_max(price, a)

print(sum(price))

Submission status: Runtime Error

Solution code:
import math

n, m = map(int, input().split())
a = list(map(int, input().split()))
a.append(0)
a.sort(reverse=True)


def waru(i, tempb):
    if a[i] >= 1:
        a[i - 1] = a[i]
        a[i] = tempb

        if a[i] < a[i + 1]:
            waru(i + 1, tempb)


while m > 0:
    a[0] /= 2
    if a[0] < a[1]:
        waru(1, a[0])
    if a[0] < 1:
        break
    m -= 1

if a[0] < 1:
    print(0)
else:
    b = []
    for i in a:
        b.append(math.floor(i))

    print(sum(b))

Submission status: Runtime Error

Solution code:
n, m = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
from collections import deque
import bisect
d = deque(A)
for _ in range(m):
    max_ = d.pop()
    tmp = max_ // 2
    index = bisect.bisect_left(d, tmp)
    d.insert(index, tmp)
print(sum(d))

Submission status: Runtime Error

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

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

a = sorted(a)[::-1]
#大きいほうから並べた。

print(a)

while m>=1:
  a[0] //= 2
  a = sorted(a)[::-1]
  m -= 1
  print(a)


print(sum(a))

Submission status: Runtime Error

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


#import scipy.optimize
import math

    
##################################################################

if __name__ == "__main__":

    Input = [input() for i in range(2)]
    N,M = list(map(int,Input[0].split()))
    A = list(map(int,Input[1].split()))
    A.sort(reverse=True)

    if N==1:
        Money = math.floor(A[0]/(2**M))
        print(Money)
    else:      
        Use = 0
        while Use < M:
            if A[0] == A[1]:
                Usenow = 1
            else:
                Usenow = math.ceil(math.log2(A[0])-math.log2(A[1]))
            Use += Usenow
            if Use > M:
                Usenow -= Use - M
            temp = math.floor(A[0]/(2**Usenow))
            for i in range(1,N):
                if temp < A[i]:
                    A[0:i] = A[1:i+1]
                    A[i] = temp
                    break
                else:
                    continue
        print(sum(A))