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:
N , M = map(int, input().rstrip().split())
 
pricelist = list(map(int, input().split()))
#moneylist = input().rstrip().split()
#pricelist.append(price)
 
for i in range(M):
  pricelist.sort()
  pricelist[0] = pricelist[0] // 2

print(sum(pricelist))

Submission status: Wrong Answer

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


def discount(i):
    if i == 0:
        if A[i] < A[i + 1]:
            i += 1
        A[i] //= 2
        return i
    else:
        if i + 1 >= N:
            i -= 1
        n_max = max(A[i - 1], A[i], A[i + 1])
        if A[i - 1] == n_max:
            i -= 1
        elif A[i] == n_max:
            i = i
        else:
            i += 1
        A[i] //= 2
        return i


if N == 1:
    A[0] //= 2 ** M
elif N == 2:
    for _ in range(M):
        discount(0)
else:
    i = 1
    for _ in range(M):
        if i == 0:
            i = 1
        i = discount(i)

print(sum(A))

Submission status: Wrong Answer

Solution code:
# -*- coding:utf8 -*-

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

Submission status: Wrong Answer

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

if N==1:
  alist[0]//=(2**N)
  print(sum(alist))
else:
  while(M>0):
    alist[0]//=2
    if alist[0]<alist[1]:
      for i in range(1,N):        
        #alist.sort(reverse=True)
        if alist[0]>alist[i]:
          #print(i)
          alist[:i],alist[i]=alist[1:i+1],alist[0]
          break
      else:
        alist[:N-1],alist[N-1]=alist[1:N],alist[0]
        #alist=alist[1:N],alist[0]
      
    M-=1
    #print(alist)
  print(sum(alist))

Submission status: Wrong Answer

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

n = 0
for _ in range(M):
    A[n] = A[n]//2
    if n == N-1 or A[n] >= A[n+1]:
        n = 0
    else:
        n += 1

print(sum(A))

Submission status: Wrong Answer

Solution code:
from bisect import bisect
from bisect import bisect_right
from bisect import bisect_left

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

ret = 0

for n in range(N):
    now_idx = N - n
    a = A[now_idx-1]

    for m in range(m_count):
        a_idx = bisect_right(A, a)
        next_buy_step = now_idx - a_idx
        if next_buy_step <= m_count:
            a = int(a/2)
            m_count -= 1
        else:
            break;
    ret += a

print(ret)

Submission status: Wrong Answer

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

a.sort()

if n == 1:
    for i in range(m):
        a[0] = a[0]//2
    print(a[0])
elif n <= 10**3:
    for i in range(m):
        a[-1] = a[-1]//2
        a.sort()
    print(sum(a))
else:
    count = -1
    count2 = -2
    for i in range(m):
        if a[count] > a[count2]: 
            a[count] = a[count]//2
        else:
            a[count2] = a[count2]//2
        if a[count] < a[count2]:
            if count == -1:
                count -= 1
                if count == count2:
                    count2 -= 1
        while 1:
            if count == -1:
                break
            if a[count] < a[count+1]:
                count += 1
            else:
                break
        while 1:
            if count2 == -1*n:
                break
            if a[count2] < a[count2-1]:
                count2 -= 1
            else:
                break
    #    print(a,count,count2)
    print(sum(a))

Submission status: Wrong Answer

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

import sys

temp = sum(A)
if temp <= 2**M:
    res = 0
    print(res)
    sys.exit()

test = [0]*N

for i in range(M):
    A.sort()
    A[-1] = A[-1] // 2
    if A == test:
        break

total = sum(A)
print(total)

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
        x = 5000
        if li[-2] >= li[-1] // (2 ** x) and m - x >= 0:
            li[-1] = li[-1] // (2 ** x)
            m -= x
        x = 2500
        if li[-2] >= li[-1] // (2 ** x) and m - x >= 0:
            li[-1] = li[-1] // (2 ** x)
            m -= x
        x = 1250
        if li[-2] >= li[-1] // (2 ** x) and m - x >= 0:
            li[-1] = li[-1] // (2 ** x)
            m -= x
        x = 625
        if li[-2] >= li[-1] // (2 ** x) and m - x >= 0:
            li[-1] = li[-1] // (2 ** x)
            m -= x
        x = 312
        if li[-2] >= li[-1] // (2 ** x) and m - x >= 0:
            li[-1] = li[-1] // (2 ** x)
            m -= x
        x = 156
        if li[-2] >= li[-1] // (2 ** x) and m - x >= 0:
            li[-1] = li[-1] // (2 ** x)
            m -= x
        x = 78
        if li[-2] >= li[-1] // (2 ** x) and m - x >= 0:
            li[-1] = li[-1] // (2 ** x)
            m -= x
        x = 39
        if li[-2] >= li[-1] // (2 ** x) and m - x >= 0:
            li[-1] = li[-1] // (2 ** x)
            m -= x
        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 bisect

N, M = map(int, input().split())
A = sorted(map(int, input().split()))[::-1]

if N == 1:
    while A[0] > 0 and M > 0:
        A[0] = A[0] // 2
        M -= 1
else:
    while True:
        for i in range(N):
            if i == 0:
                if M > 0:
                    A[i] = A[i] // 2
                    M -= 1
                compare = A[0]
                continue
            while A[i] > compare and M > 0:
                A[i] = A[i] // 2
                M -= 1
            if M <= 0 or sum(A) == 0:
                break
        else:
            continue
        break
        
print(sum(A))

Submission status: Wrong Answer

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

array.sort(reverse=True)
wareru = [0]*n     
waruru = [0]*n       

for i in range(30):
  waru = 2**(i+1)
  newarray = list(map(lambda x: x//waru, array))
  for j in range(n):
    if newarray[j]>0:
      wareru[j] += 1

sum = 0      
for i in range(30):
  gyaku=30-i
  num = wareru.count(gyaku)
  if sum + num <=m:
    sum += num
    for j in range(num):
      waruru[j] += 1
  else:
    for j in range(m-sum):
      waruru[j] += 1
    break
  
ans = 0    
for i in range(n):
  price = array[i]//(2**waruru[i])
  ans += price
  
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
inputs = sys.stdin.readlines()

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

l = [A[-1] // 2]
A[-1] = A[-1] // 2
p = -2
for _ in range(M-1):
    try:
        max_ = max(l)
        if A[p] > max_:
            l.append(A[p] // 2)
            A[p] = A[p] // 2
            p -= 1
        else:
            A[A.index(max_)] = max_ // 2
            l[l.index(max_)] = max_ // 2
    except IndexError:
        A = []
print(sum(A))

Submission status: Wrong Answer

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)-1):
            if arr[j]//2 >= arr[j+1]:
                arr[j] = arr[j] //2
                break
            else:
                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+3:
                        if arr[j+1] < arr[j+2]:
                            arr = sorted(arr,reverse=True)
                break
        print(arr)
    print(sum(arr))

Submission status: Wrong Answer

Solution code:
n, m = (int(x) for x in input().split())
a = list(map(int, input().split())) # list()でリスト化、それを変数liに代入。

a.append(0)

a.sort(reverse = True)
for i in range(m):
    for j in range(n):
        if a[j] >= a[j+1]:
            a[j] = a[j]//2
            break
        a[n]=a[n]//2

print(sum(a))

Submission status: Wrong Answer

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

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


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



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

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



print(sum(a))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math


def calc_dis(X, Y):
    Z = X / pow(2, Y)
    return math.floor(Z)


N, M = (int(x) for x in input().split())
A = ([int(x) for x in input().split()])
A = sorted(A, reverse=True)
T = [0] * N
T[0] = M
minM = -1
j = 0

while True:
    Money = 0
    for i in range(0, N):
        Money += calc_dis(A[i], T[i])
    if (minM == -1) or (minM > Money):
        minM = Money
    if j == N - 1:
        break
    elif T[j] - T[j+1] > 1:
        T[j] -= 1
        T[j+1] += 1
    else:
        j += 1

print(minM)

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
for i in range(n):
    ans += b[i]
print(ans)

Submission status: Wrong Answer

Solution code:
n, m = map(int,input().split())
a = sorted(map(int,input().split()), reverse=True)
ans = 0
m2=0

for i in range(n):
    for j in range(m+1):
        if a[i] > 2**j:
            m2 += 1
        elif a[i] <= 2**j:
            ans += a[i] -(a[i]//2**m2)
            m = m - m2
            m2 = 0

print(ans)

Submission status: Wrong Answer

Solution code:
import bisect
import numpy as np

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)

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

Submission status: Wrong Answer

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 len(a) != 0 and temp[-1] < a[-1]:
        temp.append(a.pop())
        x = ((temp[-1] / temp[-2]) // 2) + 1 
        temp[-1] //= 2 ** x
        m -= x
        temp = sorted(temp)
    else:
        temp = sorted(temp)
        temp[-1] //= 2
        m -= 1

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

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
a_list=list(map(float,input().split()))
que=sorted(a_list)

for n in range(M):
    next_keep=[]
    max_price=que.pop(-1)
    half_price=max_price/2
    
    if len(que)!=0:
        count=0
        for num in que[::-1]:
            if num>half_price:
                count-=1
            else:
                break
        que.insert(count,half_price)
    else:
        que.append(half_price)
        
ans=0
for k in range(N):
    ans+=int(que[k])
print(ans)

Submission status: Wrong Answer

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

a.sort(reverse=True)    
for i in range(n-1):
    if m==0:
        break
    while(1):
        b = a[i]//2
        c = a[i+1]//2
        if a[i]-b >= a[i+1]-c:
            a[i]=b
            m -= 1
        else:
            a[i+1]=c
            m -= 1
        if m==0:
            break
        if max(a)!=a[i] and max(a)!=a[i+1]:
            break
if n==1:
    a[0] = a[0]//2**m
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()]
print(int(round(sum(A) / 2 ** M * N, 0)))

Submission status: Wrong Answer

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

if n==1:
    for i in range(m):
        a[0]=int(a[0]/2)
    print(a[0])
    
else:
    a.sort(reverse=True)
    for i in range(m):
        a[0]=int(a[0]/2)
        if a[0]<=a[1]:
            tmp=a[1:]
            if tmp[-1]>a[0]:
                tmp.append(a[0])
                a=tmp
            else:
                insert_index = bisect.bisect_left(tmp,a[0])
                tmp.insert(insert_index-1,a[0])
                a=tmp
                  
    print(sum(a))

Submission status: Wrong Answer

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:
        Y = -(-remainM // 2)
        A[0] = A[0] // (2**Y)
        A = sorted(A, reverse=True)
        remainM = remainM - Y
        if remainM <= 0:
            break
    print(np.sum(A))

Submission status: Wrong Answer

Solution code:
import sys

A = [int(x) for x in input().split()]
#print(AB)
N = A[0]
M = A[1]
#print(N)
#print(M)
B = [int(x) for x in input().split()]
B.sort()
for i in range(M):
    B[-1] = int (B[-1] /2)
    B.sort()
print(B)


# for i in range(M):
#     max_index = B.index(max(B))
#     B[max_index] = int(B[max_index] / 2)
#     if sum(B) == 0:
#         print(0)
#         sys.exit()
    #print(B)
print(sum(B))

Submission status: Wrong Answer

Solution code:
from copy import copy
import bisect
n,m =map(int,input().split())
l_a =list(map(int,input().split()))
l_a.sort()
count = -2
for i in range(m):
    if count < -n:
        l_a[-1] = l_a[-1]//2
        count = -2
    elif l_a[-1] > l_a[count]:
        l_a[-1] = l_a[-1]//2

        x = copy(l_a[count])
        del l_a[count]
        insert_index = bisect.bisect_left(l_a[:-2],x)
        l_a.insert(insert_index,x)

        count = -2

    else:
        l_a[count] = l_a[count]//2
        count -= 1
print(sum(l_a))

Submission status: Wrong Answer

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

A.sort(reverse=True)

A[0] = A[0] / 2

for i in range(M-1) :
  n = A.index(max(A[0:i + 1]))
  A[n] = A[n] / 2
  
A = list(int(k) for k in A)

print(sum(A))

Submission status: Wrong Answer

Solution code:
n, m = (int(x) for x in input().split())
a = list(map(int, input().split())) # list()でリスト化、それを変数liに代入。

a.append(0)

a.sort(reverse = True)
for i in range(m):
    for j in range(n):
        if a[j] >= a[j+1]:
            a[j] = a[j]//2
            break

print(sum(a))

Submission status: Wrong Answer

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

n = 0
for _ in range(M):
    A[n] = A[n]/2
    if n == N-1 or A[n] >= A[n+1]:
        n = 0
    else:
        n += 1

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

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
        x = 5000
        if li[-2] >= li[-1] // (2 ** x) and m - x >= 0:
            li[-1] = li[-1] // (2 ** x)
            m -= x
        x = 2500
        if li[-2] >= li[-1] // (2 ** x) and m - x >= 0:
            li[-1] = li[-1] // (2 ** x)
            m -= x
        x = 1250
        if li[-2] >= li[-1] // (2 ** x) and m - x >= 0:
            li[-1] = li[-1] // (2 ** x)
            m -= x
        x = 625
        if li[-2] >= li[-1] // (2 ** x) and m - x >= 0:
            li[-1] = li[-1] // (2 ** x)
            m -= x
        x = 312
        if li[-2] >= li[-1] // (2 ** x) and m - x >= 0:
            li[-1] = li[-1] // (2 ** x)
            m -= x
        x = 156
        if li[-2] >= li[-1] // (2 ** x) and m - x >= 0:
            li[-1] = li[-1] // (2 ** x)
            m -= x
        x = 78
        if li[-2] >= li[-1] // (2 ** x) and m - x >= 0:
            li[-1] = li[-1] // (2 ** x)
            m -= x
        x = 39
        if li[-2] >= li[-1] // (2 ** x) and m - x >= 0:
            li[-1] = li[-1] // (2 ** x)
            m -= x
        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
    else:
        print(li[0] // (2 ** m))
        exit()
print(sum(li))

Submission status: Wrong Answer

Solution code:
import bisect
from fractions import Fraction
import math
def main():
    N,M = map(int, input().split())
    A = list(map(int, input().split()))
    A.sort(reverse=True)

    b = [0, 1]
    num = 2
    while num <= A[0]:
        b.append(num)
        num *= 2

    AAA = [0] * N
    for i in range(N):
        tmp = bisect.bisect_left(b, A[i])
        if A[i] == 1:
            AAA[i] = 1
        else:
            AAA[i] = tmp-1

    total = sum(AAA)


    rest = M
    for i in range(N):
        
        A[i] = A[i] // (2 ** round(M*Fraction(AAA[i], total)))
        rest -= round(M*Fraction(AAA[i], total))


    M = rest
    while rest > 0:
        for i in range(N):
            tmp = max(math.ceil(M*Fraction(AAA[i], total)), rest)
            A[i] = A[i] // (2 ** tmp)
            rest -= tmp
            if rest <= 0:
                break



    print(sum(A))

if __name__ == "__main__":
    main()

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
		elif bin(a[i])[2:].count("1") == 1:
			b = m
		elif i == n -1:
			b = m
		elif m > n-i:
			b = len(bin(a[i])) - 3
		else:
			b = len(bi) - 3
		if m > b:
			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 = [int(num) for num in input().split(' ')]
A = [int(num) for num in input().split(' ')]

if len(A) == 1:
  print(sum(A)//(2**(M)))
else:
  while M>=1:
    A = sorted(A,reverse=True)
    
    maxval, secondval = A[0], A[1]
    i_maxval, i_secondval = 0, 1
    if maxval == secondval:
      A[i_maxval] = maxval // 2
      M-=1
      if M==0:
        break

      A[i_secondval] = secondval // 2
      M-=1
      if M==0:
        break
        
    else:
      while maxval >= secondval:
        maxval = maxval//2
        M-=1
        if M==0:
          break
      
      if M==0:
          break
      A[i_maxval]=maxval
      for i, val in enumerate(A):
        if i==0: continue
        if val>=maxval:
          A[i] = val//2
          M-=1
          if M==0:
            break
        else:
          break
          

  print(sum(A))

Submission status: Wrong Answer

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

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

print(sum)

Submission status: Wrong Answer

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]//=2
        l+=n
    elif a[i]//2<a[i+1]:
        i+=1
    else:
        for j in range(i+1):
            a[j]//=2
        l+=i+1
for j in range(m-l):
    a[j]//=2
print(sum(a))

Submission status: Wrong Answer

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

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

    
print(sum(A))

Submission status: Wrong Answer

Solution code:
import numpy

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

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

p = 0
c = 0

while True:
    if p + 1 == len(A) or A[p] > A[p + 1]:
        A[p] =  A[p] // 2
        c += 1
        p = 0
    else:
        p += 1

    if c == M:
        break

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
flag = 0
for i in range(m):
	if (count > n - 1):
		count = 0
	if (m - 1 - i < n - 1 - count and flag == 0):
		lisA.sort(reverse=True)
		flag = 1
	if (flag == 1 and lisA[count] < half0):
		lisA.sort(reverse=True)
		half0 = lisA[0]
		count = 0
	lisA[count] /= 2
	count += 1
answer = 0
for i in range(n):
	answer += int(lisA[i])
print(answer)

Submission status: Wrong Answer

Solution code:
import bisect
import numpy as np

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

a.sort()

for i in range(n):
  if m > 0:
    mx = a.pop(-1)
    mx = mx / 2
    bisect.insort_left(a, mx)
    m -= 1
  else:
    break

a = np.floor(a)
ans = int(sum(a))


print(ans)

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
    if(n!=1 and a[-2] > a[-1]):
        swap = a[-1]
        a[-1] = a[-2]
        a[-2] = swap
print(sum(a))

Submission status: Wrong Answer

Solution code:
from bisect import bisect
from bisect import bisect_right
from bisect import bisect_left

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

ret = 0

for n in range(N):
    now_idx = N - n
    a = A[now_idx-1]

    for m in range(m_count):
        a_idx = bisect_right(A, a)
        next_buy_step = now_idx - a_idx
        if next_buy_step <= m_count:
            a = int(a/2)
            m_count -= 1
    ret += a

print(ret)

Submission status: Wrong Answer

Solution code:
import math

n,m = map(int,input().split())
if n == 1:
    a = int(input())
    for i in range (m):
        a = a // 2
    ans = a
else:
    
    a = list(map(int,input().split()))
    b = [math.log2(i) for i in a]
    list.sort(a,reverse=True)   
    list.sort(b,reverse=True)
    i = 1
    while m > 0:
        if m >= i:
            m -= i
            for j in range(i):
                b[j] -= 1
                a[j] = a[j] // 2
            if b[i-1] - b[i] < 1:
                i += 1
            
            
        else:
            list.sort(a,reverse=True)
            list.sort(b,reverse=True)
            for k in range(m):
                b[k]-=1
                a[k] = a[k] // 2
            m = 0
    ans = sum(a)
print(ans)

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]>3:
        a[i]//=2
        i+=1
        cnt+=1
    else:
        i=0
        if a[i]>3:
            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:
import bisect
import numpy as np

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)

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

Submission status: Wrong Answer

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

lista.sort(reverse=True)
#print(lista)

if n==1:
    ans=int(sum(lista)/(2**m))

else:
    for i in range(m):
        lista[0]=lista[0]/2
        lista.sort(reverse=True)
    #print(lista)    

    for i in range(m):
        lista[i]=int(lista[i])

    ans=sum(lista)
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
import math
N,M=list(map(int,input().split()))
A=list(map(int,input().split()))
#rec(N-1,M)
res=dict(Counter(A))
while M>0:
    #ex=max(list(map(float,res.keys())))
    ex=max(res.keys())
    n=res[ex]
    val=ex//2
    if n<=M:
        M-=n
        del res[ex]
        
        if val in res.keys():
            res[val]+=n
        else:
            res[val]=n
            
        
    else:
        n=M
        res[ex]-=n
        if val in res.keys():
            res[val]+=n
        else:
            res[val]=n
        M=0
    
ans=0
print(res)
for i in res.keys():
    ans+=i*res[i]
print(int(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))
    exit()

A.sort(reverse=True)

for i in range(M):
    j=0
    while A[j]<=A[j+1]:
        j+=1
        if j==N-1:
            break

    A[j]=A[j]//2


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)

m = M
maney = []
for i in a:
    if m > 1:
        maney.append(int(i / 2 ** 2))
        m = m - 2
    elif m == 1:
        maney.append(int(i / 2))
        m = m - 1
    else:
        maney.append(i)
print(sum(maney))

Submission status: Wrong Answer

Solution code:
import bisect
from fractions import Fraction
import math
def main():
    N,M = map(int, input().split())
    A = list(map(int, input().split()))
    A.sort(reverse=True)

    b = [0, 1]
    num = 2
    while num <= A[0]:
        b.append(num)
        num *= 2

    AAA = [0] * N
    for i in range(N):
        tmp = bisect.bisect_left(b, A[i])
        if A[i] == 1:
            AAA[i] = 1
        else:
            AAA[i] = tmp-1

    total = sum(AAA)


    rest = M
    for i in range(N):
        
        A[i] = A[i] // (2 ** round(M*Fraction(AAA[i], total)))
        rest -= round(M*Fraction(AAA[i], total))


    M = rest
    while rest > 0:
        for i in range(N):  
            A[i] = A[i] // (2 ** math.ceil(M*Fraction(AAA[i], total)))
            rest -= math.ceil(M*Fraction(AAA[i], total))
            if rest <= 0:
                break



    print(sum(A))

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

i = 0
if n == 1:
    while m > 0:
        a[0] //= 2
        m -= 1
else:
    while m > 0:
        # print(123)
        while a[i] >= a[i + 1] and m > 0:
            a[i] //= 2
            m -= 1
        while a[i] < a[i + 1]:
            # print(i)
            a[i], a[i + 1] = a[i + 1], a[i]
            i += 1
            if i == n - 1:
                break
        i = 0
        # print(a)

# print(a)
print(sum(a))

# import math
# import copy
# loga = copy.deepcopy(a)
# for i in range(n):
#     loga[i] = int(math.log2(a[i]))
#
# print(loga)
# loga.sort()
# loga = loga[::-1]
# print(loga)
# loga[0] -= (min(loga[0] - loga[1], m))
# m -= min(loga[0] - loga[1], m)
# print(loga, m)




# 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
#         i -= 1
#
# print(sum(a))

Submission status: Wrong Answer

Solution code:
n, m = map(int,input().split())
a = sorted(map(int,input().split()), reverse=True)
ans = 0

for i in range(n):
    for j in range(m+1):
        c = a[i]//2**j
        m2 = 0
        if c > 1:
            m2 += 1
        elif c <= 1:
            ans += a[i] -(a[i]//2**m2)
            if m - m2 == 0:
                m == 0
            else:
                m = m - m2
    else:
        m2 = 0

print(ans)

Submission status: Wrong Answer

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

# print(N)
# print(M)

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

A = sorted(A, reverse=True)
# print(A)

for i in range(M):
    # print(i)
    # print(i)
    # A[0] = int(A[0] / 2)
    # A = sorted(A, reverse=True)
    
    for j in range(N):
        if j == N - 1:
            # print(j)
            A[j] = int(A[j] / 2)
        elif A[j] > A[j + 1]:
            A[j] = int(A[j] / 2)
            break
    
print(sum(A))

Submission status: Wrong Answer

Solution code:
import numpy as np
N, M = map(int, input().split())
A = np.array(list(map(int, input().split())))
A = np.sort(A)[::-1]

if M < N:
	A = A[0:M]

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

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