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 numpy as np
%time N, M =map(int, input().split())
%time A = np.array(list(map(int, input().split())))
#print(A)
log_A = np.log2(A)

for i in range(M):
    maximum =  log_A.argmax()
    log_A[maximum] = log_A[maximum]-1
    #print(A)
A = np.power(2, log_A)
%time A = np.trunc(A)
print(int(A.sum()))

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()
cout = 0
cout_of_index = 0
cout_of_i = 0
kai = 0
def func(j):
    global list1
    global cout_of_i
    global kai
    global m
    if cout_of_i == m:
        kai = j
        return
    sd = math.floor(j/2)
    if sd >= list1[m-(cout_of_i+1)]:
        cout_of_i += 1
        func(sd)
    else:
        cout_of_i += 1
        kai = sd
        return 
    return 

if n == 1:
    print(math.floor(list1[0]/(2**m)))
    exit()
while True:
    if cout_of_i >= m:
        break
    s = max(list1)
    func(s)
    cout += kai
    list1[cout_of_index] = 0
    cout_of_index += 1
    

for i in range(cout_of_index,n):
    cout += list1[i]
print(cout)

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10000)


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


def dfs(a, m):
    if max(a) == 0:
        return 0
    if m == 0:
        return sum(a)
    a[a.index(max(a))] //= 2
    return dfs(a, m-1)


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

    print(dfs(A, M))


if __name__ == '__main__':
    main()

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(A2))
        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 = [int(i) for i in input().split()]

a.sort(reverse=True)

if n > 1:
  print(a)
  for i in range(m):
    a[0] = a[0] // 2
    a.sort(reverse=True)
    print(a)
else:
  a[0] = a[0] // (2**m)
  
print(sum(a))

Submission status: Runtime Error

Solution code:
import bisect
import math
n, m = map(int, input().split())
a = list(map(int, input().split()))
a = sorted(a)
i = 0
while i < m:
    if n > 1:
        if a[-1] > a[-2]:
            power = math.ceil(math.log2(a[-1] / a[-2]))
        else:
            power = 1
    else:
        power = 1
    a[-1] //= (2 ** power)
    popped = a.pop(-1)
    bisect.insort_right(a, popped)
    i += power
print(sum(a))

Submission status: Runtime Error

Solution code:
#D
n,m=map(int,input().split())
a=list(map(int,input().split()))
a.sort(reverse=True)
i=0
l=0
for k in range(m-1):
    if i==n-1:
        for j in range(n):
            a[j]=a[j]//2
    elif a[i]//2<a[i+1]:
        i+=1
    else:
        for j in range(i+1):
            a[j]=a[j]//2
            l+=1
for j in range(m-l):
    a[j]=a[j]//2
print(sum(a))

Submission status: Runtime Error

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

for i in range(m):
    a.sort()
    b = a[-1]/2
    count = 1
    while True:
        if b >=a[-2]:
            b /= 2
            count += 1
        else :
            break
    a[-1] = int(a[-1] / 2**count)

print(sum(a))

Submission status: Runtime Error

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

import numpy as np

def main():
    n, m_num = map(int, input().split())
    a_list = np.array([int(i) for i in input().split()])
    a_list.sort()

    def func(a, m):
        temp = a[-1]//2
        a[-1] = temp
        a.sort()
        ind = np.where(a==temp)[0][0]
        m -= 1
        if m == 0:
            print(np.sum(a))
        elif n - ind < m:
            a[a>=temp] = a[a>=temp]//2
            a.sort()
            m = m - (n-ind)
            if m>0:
                func(a, m)
            else:
                print(np.sum(a))

        else:
            a[-m:] = a[-m:]//2
            print(np.sum(a))

    func(a_list, m_num)

main()

Submission status: Runtime Error

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

ans = 0

for k in range(m):
		max(a)=max(a)//2


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

print(ans)

Submission status: Runtime Error

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

if n == 1:
    for _ in range(m):
        a[0] //=2
    print(a[0])
    exit()

temp = []
temp.append(a.pop())

while m > 0:
    if sorted(temp)[-1] < a[-1]:
        temp.append(a.pop())
    else:
        temp = sorted(temp)
        temp[-1] //= 2
        m -= 1

print(sum(temp)+sum(a))

Submission status: Runtime Error

Solution code:
import numpy as np
# import timeit

def main():
    N, M = [int(x) for x in input().split()]
    orig = np.array([int(x) for x in input().split()], dtype=np.float64)
    A = np.copy(orig)
    p = [0] * N
    for _ in range(M):
        x = np.argmax(A)
        p[x] += 1
        # 最大値が1未満 = 合計値が0
        if A[x] < 1:
            print(0)
            return
        A[x] = orig[x] / np.power(2, p[x])
    print(A.astype(np.int64).sum())

if __name__ == "__main__":
    # print(timeit.timeit(lambda: main(), number=1))
    main()

Submission status: Runtime Error

Solution code:
import numpy as np
import math

N, M = map(int, input().split())
A = list(map(int, input().split()))
A = np.array(A)
A_ix = A.argsort()[::-1]

for i in range(M):
    if(A[A_ix[0]] > A[A_ix[1]]):
        A[A_ix[0]]  =  math.floor(A[A_ix[0]] / 2)
    else:
        A_ix = A.argsort()[::-1]
        A[A_ix[0]]  =  math.floor(A[A_ix[0]] / 2)

print(A.sum())

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)

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

print(sum(a))

Submission status: Runtime Error

Solution code:
import math
n, m = (int(i) for i in input().split())
a = [int(i) for i in input().split()]

max_value = max(a)
l = math.ceil(math.log2(max_value))

b = [[] for i in range (l)]

for i in a:
    index = math.floor(math.log2(i))
    b[index].append(i)

ticket = m
p = l-1
while ticket > 0 and p >= 0:
    max_value = max(b[p])
    b[p].remove(max_value)
    if p > 0:
        b[p-1].append(max_value // 2)
    ticket = ticket - 1
    while len(b[p]) == 0 and p >= 0:
        p = p-1

print(b)

sum_value = 0
for i in range(l):
    sum_value += sum(b[i])

print(sum_value)

Submission status: Runtime Error

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


B = [[] for _ in range(40)]
max_id = 0
for a in A:
    i = len(bin(a)) - 2
    B[i].append(a)
    max_id = max(max_id, i)

B = B[:max_id+1]

j = -1
while True:
    if M == 0:
        break
    if len(B) == 1:
        break

    if len(B[j]) < M:
        M -= len(B[j])
        B[j-1].extend(list(map(lambda x: x//2, B.pop(j))))
    else:
        b = B.pop(j)
        b.sort(key=lambda x: -x)
        for k in range(M):
            B[j].append(b.pop(k)//2)
        B.append(b)
        M = 0

ans = 0
for b in B:
    ans += sum(b)
print(ans)

Submission status: Runtime Error

Solution code:
one = input()
two = input()

# one = '3 3'
# two = '2 13 8 12'

N, M = map(int, one.split())
Ar = map(int, two.split())
Ar = sorted(Ar , reverse=True)

for i in range(M):
    Ar[0] = Ar[0] / 2
    # Ar = sorted(Ar , reverse=True)
    for i in range(len(Ar)):
        if Ar[i] < Ar[i+1]:
            temp = Ar[i]
            Ar[i] = Ar[i+1]
            Ar[i+1] = temp
        else:
            break


Ar = map(int, Ar)
print(sum(Ar))

Submission status: Runtime Error

Solution code:
import sys


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


def dfs(a, m):
    if max(a) == 0:
        return 0
    if m == 0:
        return sum(a)
    a[a.index(max(a))] //= 2
    return dfs(a, m-1)


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

    print(dfs(A, M))


if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

for i in range(m):
    alst[np.argmax(alst)] = alst[np.argmax(alst)]/2.0

#print(alst)
for j in range(m):
    alst[j] = np.floor(alst[j])
#print(alst)

print(int(sum(alst)))

Submission status: Runtime Error

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

if len(a)>=2:
  while m>=1 and a[0] >= a[1]:
    a[0] //= 2
    m -= 1



for i in range(1,n+1):
  a = sorted(a)[::-1]
  #もしこれなら、これの一つ前までを順番に半分にしていく。
  if (a[0]//2)//2 <= a[i]//2 and m != 0:

    #一つずつ半分に。
    for j in range(i-1):
      a[j] //= 2
      m -= 1
      if m == 0:
        break
  



print(sum(a))

Submission status: Runtime Error

Solution code:
def binary_search(l, value):
    if len(l) == 0:
        return 0
    if len(l) < 4:
        for i in range(len(l)):
            if value <= l[i]:
                return i
    low = 0
    high = len(l) - 1
    while low <= high:
        mid = (low + high) // 2
        if l[mid-1] <= value <= l[mid]:
            return mid
        elif l[mid] < value:
            low = mid + 1
        else:
            high = mid - 1
    return mid
    
n, m = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
from collections import deque
d = deque(A)
for _ in range(m):
    max_ = d.pop()
    tmp = max_ // 2
    index = binary_search(d, tmp)
    d.insert(index, tmp)
print(sum(d))

Submission status: Runtime Error

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

A = list(map(int, input().split()))
def soujyuu(left, right, num):
    if right - left <= 1:
        A.insert(right, num)
    else:
        if num >= A[left + right // 2]:
            left = left + right // 2
        else:
            right = left + right // 2
        soujyuu(left, right, num)


A.sort()
for i in range(M):
    maxA = A.pop(N-1)
    maxA = maxA // 2
    soujyuu(0,N-2, maxA)
    #print(A)

print(sum(A))

Submission status: Runtime Error

Solution code:
# sys.stdin.readline()
import sys
import time
input = sys.stdin.readline
import math

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

# t1 = time.time()
for i in range(M):
    a = max(A) // 2
    j = A.index(max(A))
    A[j] = a
	if sum(A) <1:
		break

print(sum(A))

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
import sys

def solve(N: int, M: int, A: "List[int]"):
    A = sorted(A, reverse=True)
    m = 0
    while m < M:
        m += 1
        A[0] = A[0] // 2
        while m < M and len(A) > m and A[0] > A[M-m]:
            m += 1
            A[0] = A[0] // 2
        if (len(A) >= 2) and (A[0] < A[1]):
            tmp = A[0]
            A = A[1:]
            for i, a in enumerate(A):
                if a <= tmp:
                    A.insert(i, tmp)
                    break
                if i == len(A)-1:
                    A.insert(len(A)-1, tmp)
                    break
    print(sum(A))
    return




# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, M, A)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import bisect

n, m = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
a = a[:-100001]

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

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()] //= 2
        else:
            a[-1] //= 2
print(sum(a))

Submission status: Runtime Error

Solution code:
import numpy as np
n, m = map(int, input().split())
a = [int(i) for i in input().split(" ")]
b = np.log2(np.sort(a))
if np.sum(b//1)+n < m:
    print(0)
else:
    t = b.copy()
    c = m
    ind = n-1
    while c>0:
        if (b[ind] - b[ind-1] + 1)//1*(n-ind) <= c:
            c -= (b[ind] - b[ind-1] + 1)//1*(n-ind)
            b[ind:] -= (b[ind] - b[ind-1] + 1)//1
            ind -= 1
        else:
            for i in range(c):
                b[b.argmax()] -= 1
            c = 0
    tm = [2**i for i in t-b]
    print(int(np.sum(np.array(a)/tm//1)))

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):
    A[-1] //= 2
    for j in range(M):
        if A[j] > A[-1]:
            A[j], A[-1] = A[-1], A[j]
            break
ans = sum(A)
print(ans)

Submission status: Runtime Error

Solution code:
def A():
    w = ['Sunny', 'Cloudy', 'Rainy']
    today = input()
    index = w.index(today)
    if index == 2:
        index = -1
    print(w[index+1])

def B():
    odd = 'RUD'
    even = 'LUD'

    s = input()
    for i in range(len(s)):
        if (i+1)%2 == 0:
            if s[i] not in even:
                print('No')
                return
        else:
            if s[i] not in odd:
                print('No')
                return
        
    print('Yes')

def C():
    temp = [int(i) for i in input().split()]
    N = temp[0]
    K = temp[1]
    Q = temp[2]
    points = {}

    for i in range(N):
        points[i] = 0

    for i in range(Q):
        num = int(input())
        points[num-1] += 1

    for i in points.keys():
        if K - (Q - points[i]) > 0:
            print('Yes')
        else:
            print('No')

def D():
    temp = [int(i) for i in input().split()]
    N = temp[0]
    M = temp[1]
    A = sorted([int(i) for i in input().split()])

    #recursive solution
    def getMin(items, num_of_tickets):
        if len(items) == 0:
            return 0
        
        minimum = items[0] + getMin(items[1:], num_of_tickets)
        for i in range(1, num_of_tickets+1):
            minimum = min(minimum, items[0]//(2**i) + getMin(items[1:], num_of_tickets-i))
        return minimum

    print(getMin(A, M))
        
D()

Submission status: Runtime Error

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

for i in range(m):
    a.sort()
    b = a[-1]
    count = 0
    while True:
        if b >=a[-2]:
            b /= 2
            count += 1
        else :
            break
    a[-1] = int(a[-1] / 2**count)

print(sum(a))

Submission status: Runtime Error

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

quick_sort = lambda array: array if len(array) <= 1 else quick_sort([item for item in array[1:] if item >= array[0]]) + [array[0]] + quick_sort([item for item in array[1:] if item < array[0]])
A = quick_sort(A)

for i in range(M):
  buff = A[0] // 2
  del A[0]
  for j in range(N-1):
    if A[j] <= buff:
      A.insert(j, buff)
      break
    if(j == N-2):
        A.append(buff)

sumvalue = sum(A)
print(str(sumvalue))

Submission status: Runtime Error

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

A = np.array(A)
A = sorted(A, reverse=True)

remainM = M
n = 0
if N == 1:
    print(A[0] // (2**M))
else:
    while True:
        A[0] = A[0] // 2
        A = sorted(A, reverse=True)
        remainM = remainM - 1
        if remainM <= 0:
            break
    print(np.sum(A))

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:
    print(x)
    if x[i] < x[i+1]:
        i += 1
        max_i = np.argmax(x)
        if x[i] < x[max_i]:
            i = max_i
    if i > len(x) -1:
        break
    x[i] = np.trunc(x[i]/2.0)
    M -= 1
print(np.sum(x))

Submission status: Runtime Error

Solution code:
from functools import reduce
from operator import add

n, m = map(int, input().split())
alist = list(map(int, input().split()))
alist.sort(reverse=True)

for i in range(m):
    alist[0] //= 2
    if alist[0] < alist[1]:
        alist[0], alist[1] = alist[1], alist[0]

print(reduce(add, alist))

Submission status: Runtime Error

Solution code:
import math
from collections import deque

n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort(reverse=True)
d = deque(a)
e = deque()

i = 0
while i != m:
    l = float(d[0]/2)
    if e == deque([]):
        e.append(l)
        d.popleft()
        i += 1
    elif e[0] <= l:
        e.append(l)
        d.popleft()
        i += 1
    else:
        d.extend(list(e))
        d = list(d)
        d.sort(reverse=True)
        d = deque(d)
        e = deque()

d.extend(e)
b = list(map(math.floor, list(d)))
print(sum(b))

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
import sys

def solve(N: int, M: int, A: "List[int]"):
    A = sorted(A, reverse=True)
    m = 0
    while m < M:
        m += 1
        A[0] = A[0] // 2
        while m < M and len(A) > m and A[0] > A[M-m]:
            m += 1
            A[0] = A[0] // 2
        if (len(A) >= 2) and (A[0] < A[1]):
            tmp = A[0]
            del A[0]

            for i, a in enumerate(A):
                if a <= tmp:
                    A.insert(i, tmp)
                    break
                if i == len(A)-1:
                    A.insert(len(A)-1, tmp)
                    break
    print(sum(A))
    return




# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, M, A)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import bisect

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

while True:
    waribiki_item = A.pop(-1)
    compare = A[-1]
    waribiki_item = waribiki_item // 2
    M -= 1
    while waribiki_item >= compare and M >= 0:
        waribiki_item = waribiki_item // 2
        M -= 1
    bisect.insort(A, waribiki_item)
    if M <= 0:
        break
    
print(sum(A))

Submission status: Runtime Error

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

    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]
                    if len(arr) >= j+2 and arr[j+1] < arr[j+2]:
                        arr[j+1],arr[j+2] = arr[j+2],arr[j+1]
                break

    print(sum(arr))

Submission status: Runtime Error

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

ans = 0

for _ in range(m):
		max(a)=max(a)//2


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

print(ans)

Submission status: Runtime Error

Solution code:
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 # 空いた位置に退避していた値を挿入

n, m = (int(x) for x in input().split())
a = list(map(int, input().split())) # list()でリスト化、それを変数liに代入。
t = 0
s = 0
u = 0
'''
for i in range(m):
    a[a.index(max(a))] = a[a.index(max(a))]//2

print(sum(a))
'''

a.sort(reverse = True)
#print(a)
s = sum(a)

for i in range(m):
    t = -(-a[i] // 2)
    a[i] = a[i] // 2
    s = s - t
    insertion_sort(a)

print(s)

Submission status: Runtime Error

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

A = np.array(A)
A = sorted(A, reverse=True)

remainM = M
n = 0
if N == 1:
    print(A[0] // (2**M))
else:
    while True:
        A[0] = A[0] // 2
        A = sorted(A, reverse=True)
        remainM = remainM - Y
        if remainM <= 0:
            break
    print(np.sum(A))

Submission status: Runtime Error

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


def binary_search(arry, target):
    result = None
    left = 0
    right = len(arry) - 1

    while left <= right:
        mid = (left + right) // 2
        if arry[mid] == target:
            result = mid
            break
        elif arry[mid] > target:
            right = mid - 1
        else:
            left = mid + 1

    # print(left, right)
    if result is None:
        return left
    else:
        return result


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

A = sorted(A)

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

while M > 0:
    index = binary_search(A, A[N-1] // 2)
    for i in range(index+1):
        if M <= 0:
            break
        A[N-1-i] = A[N-1-i] // 2
        M -= 1

print(numpy.sum(A))

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(revse=True)
        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=list(map(int, input().split()))
A.index(max(A))
A.sort()
B=[A.pop()//2]
M-=1

while(M):
    if A[-1]>B[-1]:
        B.insert(0,A.pop()//2)
    else:
        b=B.pop()//2
        B.insert(0,b)
    M-=1
    
print(sum(A)+sum(B))

Submission status: Runtime Error

Solution code:
import bisect


def main():
    N, M = map(int, input().split())
    As = [int(i) for i in input().split()]

    As.sort()
    checkt_used = 0
    used = []
    while checkt_used < M:
        checkt_used += 1
        if not (N == 1 and used == []):
            if As:
                takai = As[-1]
                if used:
                    takakatta = used[-1]
                    if takai > takakatta:
                        takai = As.pop()
                    else:
                        takai = used.pop()
                else:
                    takai = As.pop()
                takai //= 2
                b_takai = As[-1]
                while checkt_used < M and b_takai < takai:
                    takai //= 2
                    checkt_used += 1
                bisect.insort_left(used, takai)
            else:
                takai = used.pop()
                takai //= 2
                b_takai = used[-1]
                while checkt_used < M and b_takai < takai:
                    takai //= 2
                    checkt_used += 1
                bisect.insort_right(used, takai)
        else:
            As[0] //= 2


    print(sum(As) + sum(used))

if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

print(A)

quick_sort = lambda array: array if len(array) <= 1 else quick_sort([item for item in array[1:] if item >= array[0]]) + [array[0]] + quick_sort([item for item in array[1:] if item < array[0]])
A = quick_sort(A)

print(A)

for i in range(M):
  buff = A[0] // 2
  del A[0]
  for j in range(N-1):
    if A[j] <= buff:
      A.insert(j, buff)
      break
    if(j == N-2):
        A.append(buff)

sumvalue = sum(A)
print(str(sumvalue))

Submission status: Runtime Error

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

cnt = 0
while cnt < m:
    if a[0] // 2 < a[1]:
        a[0] = a[0] // 2
        cnt += 1
        a.sort(reverse = True)
    else:
        a[0] = a[0] // 2
        cnt += 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)
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
    if A[0]==0:
        M=0

    i+=1

print(sum(A))

Submission status: Runtime Error

Solution code:
import bisect
import math
import sys
imput = sys.stdin

N, M = [int(item) for item in input().rstrip().split()]
As = sorted([int(item) for item in input().rstrip().split()])
cnt = 0
_t = As.pop()
while(cnt < M):
    if _t <= As[-1]:
        bisect.insort_right(As, _t)
        _t = As.pop()
    _t = _t / 2
    cnt += 1
bisect.insort_right(As, _t)
    
_sum = sum([math.floor(item) for item in As])
print(_sum)

Submission status: Runtime Error

Solution code:
str = input()

split = str.split(" ")

N = int(split[0])
M = int(split[1])

HowMuch = [0 for i in range(N)]

split = input().split(" ")
for i in range(N):
  HowMuch[i] = int(split[i])
  
sortHow = HowMuch.sort(reverse = True)

for i in range(M):
  maxInd = sortHow.index(max(sortHow))
  HowMuch[maxInd] //= 2
print(sum(HowMuch))

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 math
N, M = map(int,input().split())

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

# first coupon
max = 0
newval = A[max] >> 1
A[max] = newval

for i in range(1, M):
    next = i
    if(newval >= A[i]):
        newval >> 1
        max = 0
        A[max] = 0
        second = i
    else:
        A[i] = A[i] >> 1
        if(A[i] > A[max]):
            second = max
            max = i

print(sum(A))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import bisect
import math

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

a.sort

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


ans=0
for i in range(m):
  ans+=math.floor(a[i])
  
print(ans)

Submission status: Runtime Error

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

for i in range(m):
    a[0]=a[0]//2
    t=a[0]
    
    if n>1:
        for j in range(m):
            if a[j]<a[j+1]:
                a[j]=a[j+1]
                a[j+1]=t
            else:
                break
    
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] = a[0] // 2
    if a[0] < a[1]:
        a.sort(reverse = True)

print(sum(a))

Submission status: Runtime Error

Solution code:
import numpy as np
import math

N, M = map(int, input().split())
A = list(map(int, input().split()))
A = np.array(A)
A_ix = A.argsort()[::-1]
j = 0

for i in range(M):
    if(A[A_ix[j]] > A[A_ix[j+1]]):
        A[A_ix[j]]  =  math.floor(A[A_ix[j]] / 2)
    else:
        A_ix = A.argsort()[::-1]
        A[A_ix[j]]  =  math.floor(A[A_ix[j]] / 2)

print(A.sum())