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

A.sort(reverse=True)
sumA = sum(A)
sumP = 0
tempM = copy.deepcopy(M)
for i, a in enumerate(A):
    if M == 1 and i == 0:
        sumP += math.floor(a / (2**1))
    elif M == 1 and i != 0:
        sumP += a
    elif M > 1:
        y = round(M * (a/sumA))
        sumP += math.floor(a / (2**y))
        tempM -= y
print(sumP)

Submission status: Wrong Answer

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

while 1:
    if m > 0:
        a[0] //= 2
        tmp_max = a[0] //2
        #ここでaソート挟むか、
        m -=1
    if m == 0:
        break
    for i in range(1,n):
        if tmp_max <= a[i]:
            a[i] //= 2
            m -= 1
        if m == 0:
            break
print(sum(a))

Submission status: Wrong Answer

Solution code:
import math

import functools

def compose(*funcs):
    return functools.reduce(lambda f, g: lambda x: g(f(x)), funcs, lambda x: x)

func1 = compose(int, math.log2)
#func = compose(func1,math.floor)

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

a = list(map(func1, input().split(' ')))

for i in range(m):
    idx = a.index(max(a))
    a[idx] -= 1

ans = 0
for i in a:
    ans += int(2 ** i)

print(ans)

Submission status: Wrong Answer

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

def main():
    N, M = map(int,input().split())
    A = list(map(int,input().split()))
    B = [[] for _ in range(32)]

    Bmax = 0
    for Ai in A:
        Bi = int(math.log2(Ai))
        B[Bi].append(Ai)
        Bmax = max(Bmax, Bi)

    while M >= 0 and Bmax >= 0:
        count = len(B[Bmax])
        Bcur = min(M, count)
        for i in range(Bcur):
            B[Bmax][i] = B[Bmax][i] // 2 
            
        Bmax -= 1
        if Bmax >= 0:
            B[Bmax].extend(B[Bmax+1])
            B[Bmax].sort(key=lambda x:x, reverse=True)
            B[Bmax+1] = []
        M -= count

    Total = 0
    for Bi in B:
        for Ai in Bi:
            Total += Ai

    print(Total)




if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

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

print(money)

Submission status: Wrong Answer

Solution code:
import numpy as np

N,M=map(int,input().split())
# N,M=4,4
A = list(map(int,input().split()))
#dymmy
A.append(-1)
# A=[1,9,3,5]
# print(np.argmax(A))

# print(N,M,A)
Val = sorted(A,reverse=True)
# print("割引前",Val)

#Ｍ枚の商品券を持っているため
hoge =Val[0]

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

for i in range(M):
    # A[np.argmax(A)]= A[np.argmax(A)]//2
    Val[0]//=2
    for i in range(1,M):
        if Val[0]<Val[i]:
            Val[0],Val[i] = Val[i],Val[0]
            break
        else:
            pass

# print(Val)
print(sum(Val)+1)

Submission status: Wrong Answer

Solution code:
import numpy as np

n,m = map(int,input().split())
a_org = np.array(list(map(int,input().split())))
a_org = np.sort(a_org)[::-1]
a = np.log2(a_org)
d = np.ceil(a[0:-1] - a[1:]) * (np.arange(len(a)-1)+1)
y = np.array([0 for _ in range(n)])
x = 0
for i in range(len(d)):
    t = d[i]
    z = x
    x += t
    if(x <= m):
        # print(i)
        y[:i+1] += int(t // (i+1))
    else:
        a_org = np.floor(a_org / 2**y)
        for _ in range(m - int(z)):
            idx = a_org.argmax()
            a_org[idx] = np.floor(a_org[idx] / 2)
        x = m
        break

for _ in range(m - int(x)):
    idx = a_org.argmax()
    a_org[idx] = np.floor(a_org[idx] / 2)


# print(a)
# print(d)
# print(y)
# print(a_org)
print(int(np.sum(a_org)))

Submission status: Wrong Answer

Solution code:
n, m  = map(int, input().split())
a = list(map(int, input().split()))
# import math
# import copy
# loga = copy.deepcopy(a)
# for i in range(n):
#     loga[i] = int(math.log2(a[i]))
#
# print(loga)
a.sort()
a = a[::-1]

i = 0
while m > 0:
    if i < n - 1:
        while a[i] >= a[i - 1] and a[i] >= a[i + 1] and m > 0:
            a[i] //= 2
            m -= 1
        if a[i - 1] > a[i + 1]:
            i -= 1
        else:
            i += 1
    else:
        while a[i] >= a[i - 1] and m > 0:
            a[i] //= 2
            m -= 1
        a[i] = a[i - 1]

print(sum(a))

Submission status: Wrong Answer

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

from math import floor
from bisect import bisect

def f(x):
	if len(x) == 1:
		return x
	else:
		tmp = x[1:].copy()
		idx = bisect(tmp, x[0])
		tmp.insert(idx-1, x[0])
		return tmp

a.sort(reverse=True)

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

ans = 0
for ele in a:
	ans += floor(ele)

print(ans)

Submission status: Wrong Answer

Solution code:
M,N=[int(i) for i in input().split()]
A = [int(i) for i in input().split()]
for i in range(M):
  l=A.index(max(A))
  A[l]>>=1
print(sum(A))

Submission status: Wrong Answer

Solution code:
import numpy as np

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

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

if N > M:
    total = np.sum(As[M:])
    As = As[:M]

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

if N > M:
    print(np.sum(As) + total)
else:
    print(np.sum(As))

Submission status: Wrong Answer

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 a[i]>2:
        a[i]//=2
        i+=1
        cnt+=1
    else:
        i=0
        if a[i]>2:
            a[i]//=2
            i+=1
            cnt+=1
    if i==len(a):i=0
print(sum(a) if cnt==m else max(sum(a)-(m-cnt),0))

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left
 
N,M = map(int, input().split())
Ap = input().split()
A = [0]*N
for i in range(N):
    A[i] = int(Ap[i])
A.sort

for i in range(M):
    x = A[-1]
    x //= 2
    A[:-1].insert(bisect_left(A[:-1], x), x)
 
print(sum(A))

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
while True:
    x = A[N-1]/2
    if x < 0.5:
        break
    for i in range(N-1, -1, -1):
        if A[i] < x:
            break
        A[i] /= 2
        M -= 1
        if M == 0:
            break
    print(A)
    A.sort()
    if M == 0:
        break

sum = 0
for a in A:
    sum += a//1
print(int(sum))

Submission status: Wrong Answer

Solution code:
import heapq

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

A = list(map(int, input().split()))
A.sort()
A = A[::-1]
if N == 1 or M == 1:
    A[0] = A[0]//(2**M)
    print(sum(A))
    exit()



for i in range(N):
    A[i] *= -1

heapq.heapify(A)
m_b = M
for i in range(M):
    a = heapq.heappop(A)
    b = A[0]
    buff = a
    # mai = M-(i+1)
    c = 0
    flag = True
    for j in range(1,m_b+1):
        c += 1
        # print('-----')
        # print(a)
        a = a / (2**(j))
        a = a*-1
        a = int(a)*-1
        # print(a, j, b)
        if a > b:
            heapq.heappush(A, a)
            # heapq.heapify(A)
            # print(A)
            flag = False
            break
    if flag:
        heapq.heappush(A, a)
    m_b -= c
    if m_b < 1:
        # print(A)
        # print(sum(A))
        print(sum(A)*-1)
        # print(A)
        exit()

Submission status: Wrong Answer

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

a.sort(reverse=True)
i1 = 0
if len(a) == 1:
    while m > 0:
        a[0] = a[0] // 2
        m -= 1
else:
    while m > 0:
        if i1 == len(a)-2:
            i1 = 0
            a.sort(reverse=True)
        if a[i1] >= a[i1+1]:
            a[i1] = a[i1] // 2
            m -= 1
        if a[i1] < a[i1+1]:
            i1 += 1
        
print(sum(a))

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
*a, = sorted(map(int, input().split()))
for i in range(m):
    tmp = a.pop(-1)
    tmp /= 2
    if len(a) == 0:
        a.append(tmp)
    for j in range(len(a)):
        if tmp < a[j]:
            a.insert(j, tmp)
            break

print(sum(map(int, a)))

Submission status: Wrong Answer

Solution code:
import sys
import heapq


def solve(N: int, M: int, A: "List[int]"):
    heap = []
    asum = 0
    for a in A:
        asum += a
        heapq.heappush(heap, (- (a + 1) / 2, a, 0))

    discount = 0
    for _ in range(M):
        d0, d1, d2 = heapq.heappop(heap)
        d0 *= -1
        discount += d0
        if discount >= asum:
            break
        heapq.heappush(heap, (
            -(d0 - (d1 + 2**(d2 + 2) - 1) / 2**(d2 + 2)),
            d1,
            d2 + 1
        ))
    
    return max(0, asum - discount)


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]"
    ans = solve(N, M, A)
    if ans is not None:
        print(ans)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
import heapq


def solve(N: int, M: int, A: "List[int]"):
    heap = []
    asum = 0
    for a in A:
        asum += a
        heapq.heappush(heap, (- (a + 1) / 2, a, 0))

    discount = 0
    for _ in range(M):
        d0, d1, d2 = heapq.heappop(heap)
        d0 *= -1
        discount += d0
        if discount >= asum:
            break
        heapq.heappush(heap, (
            d0 - (d1 + 2**(d2 + 2) - 1) / 2**(d2 + 2),
            d1,
            d2 + 1
        ))
    
    return max(0, asum - discount)


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]"
    ans = solve(N, M, A)
    if ans is not None:
        print(ans)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

A = sorted(A,reverse=True)
#print(A)
X = M
for i in range(M):
    A[0] //= 2
    X -= 1
    count = 0
    for j in range(min(N-1,M)):
        if A[j] < A[j+1]:
            x = A[j]
            A[j] = A[j+1]
            A[j+1] = x
            count += 1
        else:
            break
            
    if count >= X:
        for j in range(X):
            A[j] //= 2
        break
    else:
        for j in range(count):
            A[j] //= 2
            X -= count
        A = sorted(A,reverse=True)
        
        
ans = 0
for i in A:
    ans += i

print(ans)

Submission status: Wrong Answer

Solution code:
while True:
    try:
        n, m = map(int, input().split())
        lst = list(map(int, input().split()))
        lst.sort()
        while m > 0:
            m -= 1
            temp = lst[-1] // 2
            lst[-1] = temp
            for i in range(m):
                if lst[-2-i] < temp:
                    lst.sort()
                    continue
                lst[-2-i] = lst[-2-i] // 2
                m -= 1
        print(sum(lst))
    except:
        break

Submission status: Wrong Answer

Solution code:
from sys import stdin
from bisect import insort


def main():
    N, M = [int(x) for x in stdin.readline().rstrip().split()]
    As = [int(x) for x in stdin.readline().rstrip().split()]
    As.sort()
    for _ in range(M):
        x = As[-1] / 2
        insort(As, x)
        del As[-1]
    sum_ = 0
    for x in As:
        sum_ += x
    print(sum_)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
import math
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())
L = list(map(int, sys.stdin.readline().split()))

L.append(0)
L.append(0)
L.sort(reverse=True)

memoL = 0
idx = 1
memoR = 2

for _ in range(M):
    # print(idx, memoL, memoR, L)
    val = L[idx]
    red = val // 2
    L[idx] = red
    if red < L[memoL] or red < L[memoR] :
        if L[memoL] > L[memoR]:
            idx = memoL
            memoL -= 1
        else:
            idx = memoR
            memoR += 1
"""
    if red < L[idx + 1] or red < L[idx - 1] :
        if L[idx + 1] > L[idx - 1]:
            if idx == N - 1:
                idx = 0
            idx += 1
        else:
            if idx == 0:
                idx = N - 1
            idx -= 1
"""
# print(L)
print(sum(L))

Submission status: Wrong Answer

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

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

print(int(np.sum(np.floor(A))))

Submission status: Wrong Answer

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

i = 0

for _ in range(M):
    if i + 1 < N and A[i] // 2 > A[i+1] // 2:
        A[i] //= 2
        if A[i] < A[i+1]:
            A[i], A[i+1] = A[i+1], A[i]
    else:
        A[i] //= 2
        if i < N-1:
            i += 1

print(sum(A))

Submission status: Wrong Answer

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

sorted_S = [i for i in reversed(sorted(S))]
max_index = 0

for i in range(M):

    sorted_S[0] = int(sorted_S[0]/2)
    i = 0
    for j in range(1, N):
        if sorted_S[i] < sorted_S[j]:
            sorted_S[i], sorted_S[j] = sorted_S[j], sorted_S[i]
            i += 1
        else:
            break

print(sorted_S)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
a = sorted(list([int(x) for x in input().split()]), reverse=True)

for i in range(m):
    a[0] = a[0] // 2
    if n > 1:
        if a[0] < a[1]:
            a = sorted(a, reverse=True)
sum(a)

Submission status: Wrong Answer

Solution code:
import numpy as np
n, m = map(int, input().split())
a = [int(i) for i in input().split(" ")]
b = np.array(a, dtype=np.float64)
for i in range(m):
    b[b.argmax()] /= 2
print(int(np.sum(b/1)))

Submission status: Wrong Answer

Solution code:
n,m = map(int, input().split())
lst = list(map(int, input().split()))
lst.sort(reverse=True)
num = 0
if n==1:
    for i in range(m):
        lst[0]=int(lst[0]/2)
else:
    for i in range(m):
        num=int(lst[0]/2)
        del lst[0]
        #BubbleSort
        while True:
            j=0
            if num>lst[j]:
                j+=1
            else:
                lst.insert(j,num)
                break
print(sum(lst))

Submission status: Wrong Answer

Solution code:
str_list = input().split(' ')
int_list = [int(x) for x in str_list]

N, M = int_list[0], int_list[1]

str_list = input().split(' ')
A = [int(x) for x in str_list]

import numpy as np
A = np.array(A)

if N == 1:
    print( A[0]//(2**M) )
else:
    for ii in range(M):
        index = np.argsort( A )
        first_index = np.where(index==N-1)[0]
        second_index = np.where(index==N-2)[0]
        if (A[first_index] - A[first_index] // 2) >= A[second_index] - A[second_index] // 2:
            A[first_index] = A[first_index] // 2
        else:
            A[second_index] = A[second_index] //2
print(A.sum())

Submission status: Wrong Answer

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

while 1:
    if m > 0:
        a[0] //= 2
        tmp_max = a[0]
        m -=1
    if m == 0:
        break
    for i in range(1,n):
        if tmp_max <= a[i]:
            a[i] //= 2
            m -= 1
        if m == 0:
            break
print(sum(a))

Submission status: Wrong Answer

Solution code:
import math
n,m = map(int, input().split())
a = [int(i) for i in input().split()]
a.sort(reverse = True)
discount = [] #各商品に何枚使うか
remain = m #残り枚数
if n==1:
  ans = math.floor(a[0]/(2**m))
else:
  for i in range (n-1):
    if remain>0:
      temp = a[i+1]/a[i]
      left = remain
      right = 0
      while temp >= 2**(right-left+1):
        left -= 1
        right += 1
      discount.append(left)
      remain -= left
    else:
      break
    
  ans = 0
  for i in range(len(discount)):
    ans += math.floor(a[i]/(2**(discount[i])))
  for i in range(len(discount),n):
    ans += a[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
  for j in range(1,N):
    if A[0]<A[j]:
      a=A[0]
      A[0]=A[j]
      A[j]=a
  #print(A)
ans=0
for i in range(N):
  ans+=round(A[i])
print(ans)

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
a = [int(i) for i in input().split()]
a.sort(reverse=True)
c = 0
for i in range(n):
	if m > 0:
		t = a[i]//2
		bi = bin(t)
		if len(bi) == 3:
			b = len(bi) - 2
		else:
			b = len(bi) - 3
		if m > b:
			if i == n-1:
				c += a[i] // (2**m)
				m = 0
			else:
				c += a[i]//(2**b)
				m -= b
		else:
			c += a[i]//(2**m)
			m = 0
	else:
		c += a[i]
print(c)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
i = 0
while i < m:
    a[n-1] = a[n-1] // 2
    i+=1
    if i == m:
        break
    j = 0
    while a[n-j-2] > a[n-1] and i+j < m:
        a[n-j-2] = a[n-j-2] // 2
        j+=1
    if i+j <= m:
        break
    i += j
    a.sort()

print(sum(a))

Submission status: Wrong Answer

Solution code:
while True:
    try:
        n, m = map(int, input().split())
        lst = list(map(int, input().split()))
        lst.sort()
        while m > 0:
            m -= 1
            temp = lst[-1] // 2
            lst[-1] = temp
            for i in range(m):
                if lst[-2-i] < temp:
                    lst.sort()
                    break
                lst[-2-i] = lst[-2-i] // 2
                m -= 1
        print(sum(lst))
    except:
        break

Submission status: Wrong Answer

Solution code:
import heapq

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

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

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



for i in range(N):
    A[i] *= -1

heapq.heapify(A)
m_b = M
for i in range(M):
    a = heapq.heappop(A)
    b = A[0]
    buff = a
    # mai = M-(i+1)
    c = 0
    flag = True
    for j in range(1,m_b+1):
        c += 1
        # print('-----')
        # print(a)
        a = a / (2**(j))
        a = a*-1
        a = int(a)*-1
        # print(a, j, b)
        if a > b:
            heapq.heappush(A, a)
            # heapq.heapify(A)
            # print(A)
            flag = False
            break
    if flag:
        heapq.heappush(A, a)
    m_b -= c
    if m_b < 1:
        print(sum(A)*-1)
        # print(A)
        exit()

Submission status: Wrong Answer

Solution code:
from sys import stdin
import math
import fractions
from collections import deque
from collections import Counter
import itertools

INF = 10 ** 10

# N, M <= 10^5
N, M = [int(x) for x in stdin.readline().rstrip().split()]
A = [int(x) for x in stdin.readline().rstrip().split()]

A.sort(reverse=True)

cur = 0
while (M > 0):
    if cur < N-1:
        a = A[cur] - A[cur]//2
        b = A[cur+1] - A[cur+1]//2
        if a > b:
            M = M - 1
            A[cur] -= a
            if A[cur] < A[cur+1]:
                A[cur], A[cur+1] = A[cur+1], A[cur] 
        else:
            cur += 1
    else:
        break

if M > 0:
    if M >= 30:
        A[cur] = 0
    else:    
        A[cur] = A[cur] // int(math.pow(2, M))

ans = sum(A)

print(ans)

Submission status: Wrong Answer

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

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

if(n == 1):
    print(a[0] // 2 ** m)
else:
    
    for j in range(m):
        a.sort()
        a[-1] = a[-1] // 2 
        
    
    
print(sum(a))

Submission status: Wrong Answer

Solution code:
import numpy as np

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

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

total = np.sum(As[M:])

As = As[:M]

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

print(np.sum(As) + total)

Submission status: Wrong Answer

Solution code:
from heapq import heapify,heappush,heappop
from math import ceil
n,m,*a=map(int,open(0).read().split())
if n==1:
	print(a[0]//(2**m))
	exit()
a=[(-1)*x for x in a]
x=heappop(a)
while m:
	y=heappop(a)
	while x<=y and m:
		x=ceil(x/2)
		m-=1
	heappush(a,x)
	x=y
heappush(a,x)
print((-1)*sum(a))

Submission status: Wrong Answer

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

for i in range(n[1]):
    a.reverse()
    a[0] = a[0]//2
print(sum(a))

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
A = list(map(int,input().split()))
ans = 0
use = 0
X = max(A)
Y = A.index(max(A))
for i in range(N):
    if use == M:
        break
    else:
        for j in range(M):
            if use == M:
                break
            else:
                if A[Y]!= max(A):
                    X = max(A)
                    Y = A.index(max(A))
                    break
                else:
                    A[Y] = A[Y]//2
                    use += 1
for i in range(N):
    ans += A[i]
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
while True:
    try:
        n, m = map(int, input().split())
        lst = list(map(int, input().split()))
        lst.sort()
        while m > 0:
            m -= 1
            temp = lst[-1] // 2
            lst[-1] = temp
            for i in range(m):
                if lst[-2-i] < temp:
                    break
                lst[-2-i] = lst[-2-i] // 2
                m -= 1
            else:
                lst.sort()
        print(sum(lst))
    except:
        break

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

A = sorted(A,reverse=True)
#print(A)
X = M
for i in range(M):
    A[0] //= 2
    X -= 1
    count = 0
    for j in range(N-1):
        if A[j] < A[j+1]:
            x = A[j]
            A[j] = A[j+1]
            A[j+1] = x
            count += 1
        else:
            break
            
    if count >= X:
        for j in range(X):
            A[j] //= 2
        break
    else:
        for j in range(count):
            A[j] //= 2
            X -= count
        A = sorted(A,reverse=True)
        
ans = 0
for i in A:
    ans += i

print(ans)

Submission status: Wrong Answer

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

A.sort(reverse=True)
sumP = 0

for a in A:
    y = round(M * (a/sum(A)))
    sumP += a // (2**y)

print(sumP)

Submission status: Wrong Answer

Solution code:
num = input().split()
coupon = int(num[1])

prices = input().split()
prices = sorted([int(i) for i in prices])[::-1]

for i in range(len(prices)):
  coupon_use = coupon//2 if coupon%2==0 else coupon//2+1
  prices[i] = prices[i]//(2**coupon_use)
  coupon -= coupon_use
  if coupon<=0: break
print(sum(prices))

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**6)
d = {}

def solve(N, M, A, cur, remain):
  if cur == N:
    return 0
  else:
    if not (cur, remain) in d:
      a = A[cur]
      tmp = 10**10
      for i in range(remain+1):
        tmp = min(tmp, solve(N, M, A, cur+1, remain-i)+a)
        if a / 2 < 0.5:
          break
        a //= 2
      d[(cur, remain)] = tmp
    return d[(cur, remain)]
n, m = map(int, input().split())
a = list(map(int, input().split()))
print(solve(n, m, a, 0, m))

Submission status: Wrong Answer

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

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

print(sum(A))

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
i = 0
while i < m:
    a[n-1] = a[n-1] // 2
    i+=1
    if i == m:
        break
    j = 0
    while True:
        if a[n-j-2] > a[n-1] and i+j <= m:
            a[n-j-2] = a[n-j-2] // 2
            j+=1
        else:
            break
    if i+j <= m:
        break
    i += j
    a.sort()

print(sum(a))

Submission status: Wrong Answer

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

def main():
    N, M = map(int,input().split())
    A = [[Ai, math.log2(Ai)] for Ai in list(map(int,input().split()))]
    B = [[] for _ in range(32)]

    Bmax = 0
    for Ai in A:
        Bi = int(Ai[1])
        B[Bi].append(Ai)
        Bmax = max(Bmax, Bi)

    while M >= 0 and Bmax >= 0:
        count = len(B[Bmax])
        Bcur = min(M, count)
        for i in range(Bcur):
            B[Bmax][i][0] = B[Bmax][i][0] // 2 
            
        Bmax -= 1
        if Bmax >= 0:
            B[Bmax].extend(B[Bmax+1])
            B[Bmax].sort(key=lambda x:-x[0])
            B[Bmax+1] = []
        M -= count

    Total = 0
    for Bi in B:
        for Ai in Bi:
            Total += Ai[0]

    print(Total)




if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
import math
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())
L = list(map(int, sys.stdin.readline().split()))

L.append(0)
L.append(0)
L.sort(reverse=True)

memoR = 0
idx = 1
memoL = 2

for _ in range(M):
    val = L[idx]
    red = val // 2
    L[idx] = red
    if red < L[memoL] or red < L[memoR] :
        if L[memoL] > L[memoR]:
            idx = memoL
            memoL -= 1
        else:
            idx = memoR
            memoR += 1
"""
    if red < L[idx + 1] or red < L[idx - 1] :
        if L[idx + 1] > L[idx - 1]:
            if idx == N - 1:
                idx = 0
            idx += 1
        else:
            if idx == 0:
                idx = N - 1
            idx -= 1
"""

print(sum(L))

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
a = list(map(int, input().split()))
# n, m = 4, 4
# a = [1, 9, 3, 5]
a = sorted(a, reverse=True)
# print(a)
for i in range(m):
    for j in range(n - 1):
        if a[j] > a[j + 1]:
            a[j] = a[j] // 2
            break
    else:
        a[-1] = a[-1] // 2
    # print(a)
print(sum(a))

Submission status: Wrong Answer

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

A = sorted(A,reverse=True)
#print(A)
X = M
for i in range(M):
    A[0] //= 2
    X -= 1
    count = 0
    for i in range(N-1):
        if A[i] < A[i+1]:
            x = A[i]
            A[i] = A[i+1]
            A[i+1] = x
            count += 1
        else:
            break
            
    if count >= X:
        for i in range(X):
            A[i] //= 2
        break
    else:
        for i in range(count):
            A[i] //= 2
            X -= count
        A = sorted(A,reverse=True)
        
ans = 0
for i in A:
    ans += i

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

A = sorted(A,reverse=True)
#print(A)
X = M
for i in range(M):
    A[0] //= 2
    X -= 1
    count = 0
    for i in range(N-1):
        if A[i] < A[i+1]:
            x = A[i]
            A[i] = A[i+1]
            A[i+1] = x
            count += 1
        else:
            break
            
    if count >= X:
        for i in range(X):
            A[i] //= 2
        break
    else:
        for i in range(count):
            A[i] //= 2
            X -= count
ans = 0
for i in A:
    ans += i

print(ans)