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: Wrong Answer

Solution code:
import math
import heapq

N, M = map(int, input().split())
tempA = list(map(int, input().split()))
A = []
for a in tempA:
    heapq.heappush(A, a * - 1)
for i in range(M):
    minNum = heapq.heappop(A)
    heapq.heappush(A, minNum // 2)
print(sum(A) * -1)

Submission status: Wrong Answer

Solution code:
# 他参加者の回答を参考にした．現在のAtcoderでのpythonのバージョンではdequeにinsertできないので（全ての値に-1をかけて）heapqがよさそう？
import bisect
N, M = map(int, input().split())
B = [int(x) for x in input().split()]
A = sorted(B, reverse=True)
ite = 0
for i in range(M):
    A[ite] //= 2
    if ite < N - 1:

        if A[ite] < A[ite + 1] and A[0] < A[ite+1]:
            ite += 1
    else:
        A = sorted(A, reverse=True)
        ite = 0

ans = sum(A)
print(ans)

Submission status: Wrong Answer

Solution code:
import heapq

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

ans = []
for i in range(n):
    heapq.heappush(ans, -a[i])
print(ans)

for i in range(m):
    temp = -heapq.heappop(ans)
    heapq.heappush(ans, -(temp//2))

print(-sum(ans))

Submission status: Wrong Answer

Solution code:
import bisect

N, M = map(int, input().split(" "))
As = [0]+list(map(int, input().split(" ")))
As = sorted(As)
cnt = 0
cnt2 = 1
j = 0
for _ in range(M):
  if j >= As[-1-cnt]:
    i = j//2
  else:
    i = As[-1-cnt]//2
    
  j = i
  
  if i < As[-1-cnt-1]:
    cnt += 1
    cnt2 = 1
    bisect.insort_left(As,i)
  else:
    cnt2 += 1

print(sum(As[:-cnt]))

Submission status: Wrong Answer

Solution code:
import numpy as np
import math

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

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

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

print(int(math.floor(sum(a))))

Submission status: Wrong Answer

Solution code:
# プライオリティキューの利用
import heapq
n, m = map(int, input().split())
a = list(map(int, input().split()))
# 最大の値段を取り出すために、全て(-1)を掛ける
a = list(map(lambda x: x * (-1), a))
heapq.heapify(a)
# 割引券を使い切るまで行う
while m != 0:
    # 最大の値段を取り出す
    price = heapq.heappop(a)
    # 割引
    price //= 2
    m -= 1
    # プライオリティキューへ戻す
    heapq.heappush(a, price)
# 最初に(-1)掛けているので、符号を戻す
print(sum(a) * (-1))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#他参加者の回答を参考にした．現在のAtcoderでのpythonのバージョンではdequeにinsertできないので（全ての値に-1をかけて）heapqがよさそう？
import bisect
N, M = map(int, input().split())
B = [int(x) for x in input().split()]
A = sorted(B, reverse=True)
ite = 0
for i in range(M):
    if ite < N - 1:
        A[ite] //= 2
        if A[ite] < A[ite + 1] and A[0] < A[ite+1]:
            ite += 1
        else:
            A = sorted(A, reverse=True)
            ite = 0

ans = sum(A)
print(ans)

Submission status: Wrong Answer

Solution code:
N, M = list(map(int, input().split(' ')))
As = list(map(int, input().split(' ')))
As = sorted(As)[::-1]
while M:
    if len(As) == 1:
        while M > 0:
            As[0] = As[0] // 2
            M -= 1
            
    for i in range(len(As) - 1):
        # do while ...
        while(As[i] >= As[i+1]) and M > 0:
            As[i] = As[i] // 2
            M -= 1
print(sum(As))

Submission status: Wrong Answer

Solution code:
import heapq

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

if n > 1:
  for i in range(m):
    a = heapq.heappop(aaa) // 2
    heapq.heappush(aaa, a)
else:
  print(aaa[0] // (2 ** m))
  
print(sum(aaa))

Submission status: Wrong Answer

Solution code:
import heapq

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

ans = []
for i in range(n):
    heapq.heappush(ans, -a[i])

for i in range(m):
    temp = heapq.heappop(ans)
    heapq.heappush(ans, temp//2)
print(-sum(ans))

Submission status: Wrong Answer

Solution code:
N, M = list(map(int, input().split(' ')))
As = list(map(int, input().split(' ')))
#  priority queue is dead!
As = sorted(As)[::-1]
while M:
    if len(As) == 1:
        while M > 0:
            As[0] = As[0] // 2
            M -= 1
            
    for i in range(len(As) - 1):
        # do while ...
        As[i] = As[i] // 2
        M -= 1
        while(As[i] >= As[i+1]) and M > 0:
            As[i] = As[i] // 2
            M -= 1
print(sum(As))

Submission status: Wrong Answer

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


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

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

A = sorted(A)

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

print(sum(A))

Submission status: Wrong Answer

Solution code:
import numpy as np


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

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
l=list(map(int,input().split()))
import heapq
q=[]
for i in l:
  heapq.heappush(q,-i)
for i in range(m):
  n=heapq.heappop(q)
  if n%2==0:
    n=n//2
  else:
    n=n//2+1
  heapq.heappush(q,n)
sum=0
for i in range(n):
  sum+=-q[i]
print(sum)

Submission status: Wrong Answer

Solution code:
import time
import sys
import heapq

input = sys.stdin.readline

N, M = map(int, input().split())
A = list(map(int, input().split()))
start = time.time()
ans = []
for a in A:
    heapq.heappush(ans, -a)

for _ in range(M):
    l = heapq.heappop(ans)
    heapq.heappush(ans, -(-l)//2 )

print(-sum(ans))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
import heapq

input = sys.stdin.readline

N, M = map(int, input().split())
A = list(map(int, input().split()))
ans = []
for a in A:
    heapq.heappush(ans, -a)

for m in range(M):
    l = heapq.heappop(ans)
    heapq.heappush(ans, (-l)//2 )

print(-sum(ans))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import heapq
n,m=map(int,input().split())
a=list(map(int,input().split()))
for i in range(m):
    heapq.heapify(a)
    a[n-1]=a[n-1]//2
ans=0
for i in range(n):
    ans+=a[i]
print(ans)

Submission status: Wrong Answer

Solution code:
import math

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

import heapq
heap = []
for a in A:
    heapq.heappush(heap, -1*a)
    
for _ in range(M): 
    v = heapq.heappop(heap)
    heapq.heappush(heap, round(v/2))
    
print(-1*sum(heap))

Submission status: Wrong Answer

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

if n == 1:
    print(a[0]//(2*m))

else:
    a.sort(reverse = True)
    cnt = sum(a)
    c = [0] * n
    for i in range(m):
        x = c[0]
        jj = 0
        aa = a[0]//(2**c[0])- a[0]//(2**(c[0] +1))
        for j in range(1,n):
            if c[j] == x:
                if x == 0:
                    break

            else:
                x -= 1
                if  aa <=  a[j]//(2**c[j])- a[j]//(2**(c[j] +1)):
                    aa = a[j]//(2**c[j])- a[j]//(2**(c[j] +1))
                    jj = j
        cnt -= aa
        c[jj] += 1

    print(cnt)

Submission status: Wrong Answer

Solution code:
tmp = list(map(int,(input().split())))
n = tmp[0]
m = tmp[1]

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

sum = 0

while (m > 0): 
  ai.sort(reverse=True)
  for i in range(n-1):
    if ai[i] >= ai[i+1] and m > 0 :
      m -= 1
      ai[i] = ai[i] // 2

for i in range(n):
  sum += ai[i]

#print(ai)
print(sum)

Submission status: Wrong Answer

Solution code:
import bisect

n, m = map(int, input().split())
a = map(int, input().split())
a = sorted(list(a))
scope = []
digit = len(bin(a[-1]))
for _ in range(n):
    if len(bin(a[-1])) == digit:
        scope.append(a.pop())
    else:
        digit -= 1
        break
while m != 0:
    for i in range(len(scope)):
        if m == 0:
            break
        scope[i] = scope[i] >> 1
        m -= 1
    for _ in range(len(a)):
        if len(bin(a[-1])) == digit:
            bisect.insort(scope, a.pop())
        else:
            digit -= 1
            break
print(sum(scope) + sum(a))

Submission status: Wrong Answer

Solution code:
import numpy as np


n, m = map(int, input().split())
sum = 0
a = np.array(list(map(int, input().split())))
for i in range(m):
    np.sort(a)[::-1]
    a[0] /= 2
b = np.array([abc // 1 for abc in a])
print(sum)

Submission status: Wrong Answer

Solution code:
N, M = list(map(int, input().split(' ')))
A = list(map(int, input().split(' ')))
A.sort(reverse=True)
#print(*A)
k = 0
while k < M:
    flag = 0
    A[0] //= 2
    tmp = A[0]
    k += 1
    i = 1
    while i < N:
        if k >= M:
            flag = 1
        if tmp < A[i]:
            break
        else:
            A[i] //= 2
            k += 1
            i += 1
    if flag == 1:
        break
    #print(*A)
    A.sort(reverse=True)
#print(*A)
print(sum(A))

Submission status: Wrong Answer

Solution code:
import bisect

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

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

Submission status: Wrong Answer

Solution code:
n, m = list(map(int, input().split()))
lisA = [int(i) for i in input().split()]
#print(n, m)
#print(lisA)

lisA.sort(reverse=True)
half0 = lisA[0]
count = 0
for i in range(m):
	if (count > n - 1):
		count = 0
	if (lisA[count] < half0):
		lisA.sort(reverse=True)
		half0 = lisA[0]
		count = 0
	lisA[count] /= 2
	count += 1
print(int(sum(lisA)))

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
for i in range(m):
    a[n-1] //= 2
    j=n-1
    while(j>0 and a[j] > a[n-1]):
        j-=1
    a.insert(j, a[n-1])
    del a[-1]
print(sum(a))

Submission status: Wrong Answer

Solution code:
import numpy as np
def main():
    # 1文字に省略

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


main()

Submission status: Wrong Answer

Solution code:
import bisect
import numpy as np
import array

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

a.sort()
a = array.array('f', a)


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

nums = np.array(a)
print(int(sum(np.round(nums, 0))))

Submission status: Wrong Answer

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-1]=A[N-1]/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: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import numpy as np
N, M = map(int, input().split())
A = np.array(np.log2(sorted(list(map(int, input().split())), reverse=True)).astype(np.float64))
#print(A)
while True:
    A_m = np.where(A >= int(A[0]))
    if len(A_m[0]) <= M:
        A[A_m] -= 1.
        A = np.sort(A)[::-1]
        M -= len(A_m[0])
        #print(A, M)
    else:
        A[:M] -= 1.
        break
    if A[0] < 0:
        break
#print(A)
A = (2 ** A).astype(np.int64)
#print(A)
print(np.sum(A))

Submission status: Wrong Answer

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

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


A.sort()

for _ in range(M):
    A[N-1] = A[N-1] // 2
    if A[N-1] < A[N-2]:
      a = A[N-1]
      A[N-1] = A[N-2]
      A[N-2] = a
     
print(sum(A))

Submission status: Wrong Answer

Solution code:
import math
N, M = [int(x) for x in input().split()]
A =sorted([ int(x) for x in input().split() ])[::-1]
C = [ int(math.log2(int(x))) for x in A ] 
k = sum(C) -M
p = [1]*N
while True:
  for i in range(len(p)):
    p[i] = p[i]*2
    k -= 1
    #print(p)
    if k == 0:
      print(sum(p))
      exit()

Submission status: Wrong Answer

Solution code:
# coding:utf-8

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

item = list(map(int, input().split()))
item.sort()
item = item[::-1]
price = 0
if len(item) > 1:
    for i in range(len(item)):
        Y = 0
        while True:
            if M > 0:
                Y += 1
                M -= 1
                pr = int(item[i]/(2**Y))
                npr = int(item[i]/(2**(Y+1)))
                if M <= 0:
                    price += pr
                    break
                elif npr <= item[-1] and M > 0:
                    price += pr
                    # print(pr)
                    break
                else:
                    pass

            else:
                price += item[i]
                break
else:
    pr = int(item[0]/(2**M))
    price = pr
print(price)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
li = list(map(int,input().split()))
while m>0:
  for i in range(len(li)):
    if  li[i]==max(li):
      li[i]=li[i]//2
      break
  m-=1
print(li)

Submission status: Wrong Answer

Solution code:
from sys import stdin
import math

n,m = [int(x) for x in stdin.readline().rstrip().split()]
li = list(map(int,stdin.readline().rstrip().split()))
li.sort(reverse=True)
kaisu = 0
if n > 2:
    for i in range(n-1):
        while kaisu < m+1:
            if li[i] >= li[i+1]:
                li[i] = math.floor(li[i]/2)
                kaisu += 1
            else:
                break
    print(sum(li))
if n == 1:
    yu = li[0] 
    while yu>0 and kaisu<m+1:
        yu = math.floor(yu/2)
        kaisu += 1
    print(yu)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

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

if N > 10000:
    cnt = 0
    while cnt < M:
        A = np.sort(A)
        for i in range(100):
            max_ind = A[N-100:N].argmax()
            A[max_ind] //= 2
            cnt += 1

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

print(sum(A))

Submission status: Wrong Answer

Solution code:
N, M = [int(n) for n in input().split()]
A = sorted([int(n) for n in input().split()], reverse=True)
for _ in range(M):
    A[0] //= 2
    if len(A)!=1:
        if A[0] < A[1]:
            idx = A.index(max(A))
            A[0], A[idx] = A[idx], A[0]
print(sum(A))

Submission status: Wrong Answer

Solution code:
import bisect

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

cnt = 1
while cnt <= M:
    x = bisect.bisect_left(A, A[-1]/2)
    for i in range(x + 1):
        A[-i -1] /= 2
        cnt += 1
        if cnt > M:
            break

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

Submission status: Wrong Answer

Solution code:
import math

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

import heapq
heap = []
for a in A:
    v = (-float(math.log(a,2)))
    heapq.heappush(heap, v)
for _ in range(M): 
    v = heapq.heappop(heap) + 1
    heapq.heappush(heap, v)
    
cnt = 0
for h in heap:
    cnt += math.floor(2**-h)
    
print(cnt)

Submission status: Wrong Answer

Solution code:
n=[3,3]
m=[2,13,8]
maxm=sum(m)
for i in range(n[1]):
  m[m.index(max(m))]=m[m.index(max(m))]//2

print(sum(m))

Submission status: Wrong Answer

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

A.sort()
A.reverse()
if N == 1:
    total_price += A[N-1]//(2**M)
else:    
    for i in range(N-1):
        if 0 < M:
            y = 0
            tmp = A[i]
            while A[i+1]//2+A[i+1]//4 < A[i]//2+A[i+1]//2 and 0 < M:
                A[i] = A[i]/2
                y += 1
                M -= 1
            total_price += tmp//(2**y)
            # print(tmp,total_price,y,M)
        else:
            total_price += A[i]
    total_price += A[N-1]//(2**M)

print(total_price)

Submission status: Wrong Answer

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)
  del A2[-1]
  idx = bisect.bisect_left(A2,tmp_a)
  A2 = A2[:idx] + [tmp_a] + A2[idx+1:]
print(sum(A[:N-M])+sum(A2))

Submission status: Wrong Answer

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 < len(List):
    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 = len(List)+1
                c = M+1
                break
        if c > M:
            break
    cnt += 1
    if cnt == len(List) and c < M:
        cnt = len(List)-1
            
ans = 0
for i in range(len(List)):
    ans += sum(List[i])
            
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
N,M = map(int,input().split())
A = list(map(int,input().split()))
cut = np.asarray([2**i for i in range(M+1)])
tmp = np.zeros(M+1,dtype="int")
dp = np.zeros(M+1,dtype="int")
dp[:] = A[0]//cut[:]

for i in range(1,N):
  cost = A[i]//cut[:]
  for j in range(M+1):
    tmp[j] = min(dp[0:j+1]+cost[0:j+1][::-1])
  dp = tmp
print(dp[-1])

Submission status: Wrong Answer

Solution code:
from math import log, ceil

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

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

ans = 0
for i in range(N-1):
    # i番目に使う枚数
    if A[i+1]//2 == 0:
        m = M
    else:
        m = ceil(log(A[i]//(A[i+1]//2), 2))
    if m > M:
        m = M
    if m == M:
        if A[i] // (2 ** m) + A[i + 1] > A[i] // (2 ** (m - 1)) + A[i + 1] // 2:
            m -= 1
    M -= m
    ans += A[i] // (2 ** m)
else:
    # 最後は残ってる枚数を全部使う
    ans += A[-1] // (2 ** M)

print(ans)

Submission status: Wrong Answer

Solution code:
N,M = map(int, input().split())
A = list(map(int, input().split()))
 
def second_large(x):
    y = x.copy()
    y.remove(max(y))
    return max(y)
 
if N>=2:
  while M>=1:
    fm_n = max(A)
    sm_n = second_large(A)
    div_m = fm_n/sm_n
    i=1
    while 2**(i+1)<=div_m:
      i+=1
 
    if M>=i:
      if M-i>=1:
        A[A.index(max(A))]=fm_n//(2**(i+1))
        M -= (i+1)
      else:
        A[A.index(max(A))]=fm_n//(2**i)
        M -= i
    else:
      A[A.index(max(A))]=fm_n//(2**M)
      M = 0
 
  print(sum(A))
else:
    i=1
    while 2**(i+1)<=A[0]:
      i+=1
    if M>=i:
      print(0)
    else:
      print(A[0]//2**M)

Submission status: Wrong Answer

Solution code:
import heapq
N,M= list(map(lambda x: int(x),input().split()))

lst = list(map(lambda x: -int(x),input().split()))


for i in range(M):
    a = heapq.heappop(lst)
    a = a/2.0
    heapq.heappush(lst,a)

ans=0
for i in lst:
    ans += i//1
print(ans)

Submission status: Wrong Answer

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

dic = {}
for i in range(31):
    dic[i] = []

i2 = 0

for i in range(len(lista)):
    while(lista[i]>=2**(i2+1)):
        i2+=1
    dic[i2].append(lista[i])
    
#print(dic)

end = False
for t in range(i2,0,-1):
    list_d = dic[t]
    list_d.sort()
    loop = len(list_d)
    if loop<m:
        for i in range(loop):
            list_d[i] = list_d[i]/2
        dic[t-1] = dic[t-1]+list_d
        list_d = []
        m = m-loop
        dic[t] = list_d

    else:
        tlist = []
        for i in range(loop):
            tmp = list_d[-1]
            #dic[t-1].append(tmp/2)
            tlist.append(tmp/2)
            #list_d =  list_d[:-1]
            m = m-1
            if m==0:
                end = True
                list_d = list_d[:int(-1.0*i)]
                dic[t-1] = dic[t-1]+tlist
                dic[t] = list_d
                break
        list_d = []
    
    if end == True:
        break
        
        
"""print(dic)
print(m)"""
ans = 0
if m > 0:
    ans = n-m
    if ans >= 0:
        print(n-m)
    else:
        print(0)
else:
    for i in range(t+1):
        list_d = dic[i]
        #print(i,list_d)
        for l in range(len(list_d)):
            tmp = list_d[l]
            ans+=int(tmp)
    print(ans)

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
a = list(map(int,input().split()))
b = sorted(a,reverse=True)
ans = 0
if n == 1:
    b[0] //= 2**m
else:
    while m > 0:
        c = b[0]
        b[0] //= 2
        m -= 1
        if b [0] <= b[1]:
            b[0],b[1] = b[1],b[0]
            for i in range(n):
                if b[0] < b[i]:
                    b[0],b[i] = b[i],b[0]
                    break
                elif b[i] < b[1]:
                    break
for i in range(n):
    ans += b[i]
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import bisect
N,M=[int(i) for i in input().split()]
A = sorted([int(i) for i in input().split()])
print(A)
for i in range(M):
  A2=A[N-1]//2
  A.pop(N-1)
  A.insert(bisect.bisect_left(A, A2), A2)
#  print(A)
print(sum(A))