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:
# -*- 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+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] = B[Bmax][i] // 2 
            
        Bmax -= 1
        if Bmax >= 0:
            B[Bmax].extend(B[Bmax+1])
            B[Bmax].sort(key=lambda x:-x)
            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] = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]

A.sort(reverse = True)

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

print(sum(A))

Submission status: Wrong Answer

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

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

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

sum = 0
for i in range(N):
    q, mod = divmod(A[i], (2**count_discount[i]))
    sum += q
print(sum)

Submission status: Wrong Answer

Solution code:
import numpy as np
N, M = map(int, input().split())
A = [int(x) for x in input().split()]
for i in range(M):
  A[A.index(max(A))] = max(A) // 2
np.sum(A)

Submission status: Wrong Answer

Solution code:
import 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 += a // 2
    elif M == 1 and i != 0:
        sumP += a
    elif M > 1 and tempM > 0:
        y = round(M * (a/sumA))
        sumP += a // (2**y)
        tempM -= y
    elif M > 1 and tempM == 0:
        sumP += a
print(sumP)

Submission status: Wrong Answer

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

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:
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[n] = A[n] // (2**Y)
        remainM = remainM - Y
        if A[n] <= A[n+1]:
            n += 1
        if remainM <= 0:
            break
    print(np.sum(A))

Submission status: Wrong Answer

Solution code:
N, M = (int(n) for n in input().split())
A = list((int(a) for a in input().split()))
A.sort()
A.reverse()
while(M>0):
    A[0] = int(A[0]/2)
    if len(A)>1 and A[0]<A[1]:
        tmp = A[0]
        A[0] = A[1]
        A[1] = tmp
    M-=1
print(sum(A))

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
l=sorted(list(map(int,input().split())))
l1=[]
for i in range(n):
  num=l[i]
  count=0
  while num!=0:
    num//=2
    count+=1
  l1.append(count)
sum=0
for i in range(n):
  sum+=l1[i]
if sum<=m:
  print(0)
else:
  if count%n==0:
    num=count//n
  else:
    num=count//n+1
  lcount=[0 for i in range(n)]
  for i in range(1,n+1):
    if m==0:
      break
    else:
      lcount[-i]=min(l1[-i]-num,m)
      m-=lcount[-i]
      l1[-i]=num
  sum=0
  for i in range(n):
    sum+=l[i]//(2**lcount[i])
  print(sum)

Submission status: Wrong Answer

Solution code:
# D - Powerful Discount Tickets
inputNum = list(map(int, input().split()))
N = inputNum[0]
M = inputNum[1]

A = list(map(int, input().split()))
A.sort(reverse=True)
index = 0
maxValue = A[index]

for i in range(M - 1):
    A[index] //= 2
    maxValue //= 2
    for j in range(N):
        if maxValue < A[j]:
            maxValue = A[j]
            index = j
            break
A[index] //= 2

print(sum(A))

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
A = list(map(int,input().split()))
Aguu = []
for x in A:
    if x%2 != 0:
        Aguu.append(x-1)
    else:
        Aguu.append(x)
# print(Aguu)
for i in range(M):
    Aguu[Aguu.index(max(Aguu))] /= 2
# print(Aguu)
print(int(sum(Aguu)))

Submission status: Wrong Answer

Solution code:
class Heap:
    
    def maintain_heapify(self,A,i):
        l=2*i+1
        r=2*i+2
        if self.name=='max':
            if l<len(A) and A[l]>A[i]:
                largest=l
            else:
                largest=i
            
            if r<len(A) and A[r]>A[largest]:
                largest=r
            
            if largest!=i:
                A[largest],A[i]=A[i],A[largest]
                self.maintain_heapify(A,largest)

        elif self.name=='min':
            if l<len(A) and A[l]<A[i]:
                smallest=l
            else:
                smallest=i
            if r<len(A) and A[r]<A[smallest]:
                smallest=r
            if smallest!=i:
                A[smallest],A[i]=A[i],A[smallest]
                self.maintain_heapify(A,smallest)

    def build_heap(self,A):
        i=len(A)//2
        while i>=0:
            self.maintain_heapify(A,i)
            i-=1

    def __init__(self,A,name='max'):
        self.name=name
        self.build_heap(A)
        self.heap=A

    def insert(self,v):
        self.heap.append(v)
        self.build_heap(self.heap)

    def deleteroot(self):
        root=self.heap[:1]
        tmp=self.heap[1:len(self.heap)-1]
        self.heap=self.heap[len(self.heap)-1:]+tmp
        self.build_heap(self.heap)
        return root[0]

    def get_root(self):
        return self.heap[0]
    def get_sum(self):
        return sum(self.heap)


def main():
    N,M = map(int,input().split())
    A = list(map(int,input().split()))
    heap = Heap(A)
    tmp = 0
    for cnt in range(M):
        first = heap.deleteroot()
        plus = first // 2
        heap.insert(plus)
    print(heap.get_sum())
    return
main()

Submission status: Wrong Answer

Solution code:
listA=[] #appendのために宣言が必要
while True:
    try:
        listA.append(list(map(int,input().split())))

    except:
        break;
        #または、quit(),os.exit()をして止める。

n,m=listA[0]

maxA=sorted(listA[1])
kei=0
kei_list=[]
j=0
for j in range(m,0,-1):
    for i in range(n):
        kei=kei + maxA[-i]//(2**(m-j))
        j=j-1
    kei_list.append(kei)
        
print(min(kei_list))

Submission status: Wrong Answer

Solution code:
import bisect

N,M =map(int,input().split())
A =[int(i) for i in input().split()]
N += 1
A.append(0)
A.sort()
ans = [0]*N
num = 0
ma = A[-1]//2
while True:
    inde = bisect.bisect_left(A,ma-1)
    if num + (N-inde) < M:
        ans[-1] += 1
        ans[max([inde-1,0])] -=1
        num += (N-inde)
        if ma == 0:
            break
    else:
        ans[-1] += 1
        ans[N-(M-num)-1] -= 1
        break
    ma = ma//2

answer = 0
for i in range(N):
    i = N-i-1
    answer += A[i]//(2**ans[i])
    ans[i-1] += ans[i]

print(int(answer))

Submission status: Wrong Answer

Solution code:
N,M=[int(thing) for thing in input().split(" ")]
A_list=[int(thing) for thing in input().split(" ")]
sogaku=sum(A_list)
A_list.sort(reverse=True)
i=0
for aaaaa in range(M):
    exp=max(A_list)
    ind=A_list.index(exp)
    A_list[ind]=A_list[ind]*0.5
print(sum([thing//1 for thing in A_list]))

Submission status: Wrong Answer

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

Alist = sorted(Alist, reverse=True)
for i in range(M):
    Alist[0] = Alist[0]//2
    Alist = sorted(Alist, reverse=True)

Submission status: Wrong Answer

Solution code:
import math
n, m = map(int, input().split())
a = sorted(map(int, input().split()), reverse=True)
i = 1
while m > 0:
	if m>=i:
		m -= i
		a[0:i] = [num//2 for num in a[0:i]]
		if i < n-1 and a[i-1]<a[i]:
			temp = a[i]
			a[1:i+1] = a[0:i]
			a[0] = temp
			i += 1
	else:
		a[0:m] = [num//2 for num in a[0:m]]
		m=0
print(sum(a))

Submission status: Wrong Answer

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

ded = 1
cost0 = [None for m in range(M + 1)]
for m in range(M, -1, -1):
    cost0[m] = A[0] // ded
    ded *= 2

for i in range(1, N):
    cost1 = [None for m in range(M + 1)]
    for m0 in range(len(cost0)):
        ded = 1
        for m1 in range(m0 + 1):
            c = cost0[m0] + A[i] // ded
            if cost1[m1] is None or cost1[m1] > c:
                cost1[m1] = c
            ded *= 2
    cost0 = cost1
print(min(cost0))

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)
A.append(0)
for i in range(N):
    if M<=0:
        break
    Max1 = math.log2(A[i])
    Max1 = math.floor(Max1)
    tmp_now = A[i]//2**Max1
    tmp_if = A[i]//2**(Max1-1)
    if tmp_if-tmp_now < A[i+1]-A[i+1]//2:
        cnt = Max1-1
    else:
        cnt = Max1
    cnt = min(cnt,M)
    M-=cnt
    A[i] = A[i]//2**cnt
A.pop(-1)
if M>0:
    A[-1] = A[-1]//2**cnt
print(int(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()]

for i in range(M):
  A = sorted(A)
  A[0] = A[0] // 2

print(sum(A))

Submission status: Wrong Answer

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


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from math import log2,ceil
class Heap:
    
    def maintain_heapify(self,A,i):
        l=2*i+1
        r=2*i+2
        if self.name=='max':
            if l<len(A) and A[l]>A[i]:
                largest=l
            else:
                largest=i
            
            if r<len(A) and A[r]>A[largest]:
                largest=r
            
            if largest!=i:
                A[largest],A[i]=A[i],A[largest]
                self.maintain_heapify(A,largest)

        elif self.name=='min':
            if l<len(A) and A[l]<A[i]:
                smallest=l
            else:
                smallest=i
            if r<len(A) and A[r]<A[smallest]:
                smallest=r
            if smallest!=i:
                A[smallest],A[i]=A[i],A[smallest]
                self.maintain_heapify(A,smallest)

    def build_heap(self,A):
        i=len(A)//2
        while i>=0:
            self.maintain_heapify(A,i)
            i-=1

    def __init__(self,A,name='max'):
        self.name=name
        self.build_heap(A)
        self.heap=A

    def insert(self,v):
        self.heap.append(v)
        self.build_heap(self.heap)

    def deleteroot(self):
        root=self.heap[:1]
        tmp=self.heap[1:len(self.heap)-1]
        self.heap=self.heap[len(self.heap)-1:]+tmp
        self.build_heap(self.heap)
        return root[0]

    def get_root(self):
        return self.heap[0]
    def get_sum(self):
        return sum(self.heap)


def main():
    N,M = map(int,input().split())
    A = list(map(int,input().split()))
    heap = Heap(A)
    tmp = 0
    for cnt in range(M):
        first = heap.deleteroot()
        plus = first // 2
        heap.insert(plus)
    print(heap.get_sum())
    return
main()

Submission status: Wrong Answer

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


print(sum(a))

Submission status: Wrong Answer

Solution code:
import math

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

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

money = 0

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

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

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

print(money)

Submission status: 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):
        x = solve(N, M, A, cur+1, remain-i)+a
        if tmp < x:
          break
        else:
          tmp = x
        if a / 2 < 0.5:
          break
        a //= 2
      d[(cur, remain)] = tmp
    return d[(cur, remain)]

n, m = map(int, input().split())
a = sorted(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 = list(reversed(sorted(a)))
ans = 0
#minV = 10**15
total = sum(a)

while True:
    if m <= 0:
        break
    maxV = max(a)
    total = total - maxV + maxV // 2

#    a[0] = a[0] // 2
#    a = list(reversed(sorted(a)))
    m -= 1

ans = sum(a)
print(ans)

Submission status: Wrong Answer

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

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

for i in range(M):
    a = math.floor(max(A) % 2)
    j = A.index(max(A))
    A[j] = a


print(sum(A))

Submission status: Wrong Answer

Solution code:
#S = input()
N,M = map(int,input().split())
A_list = list(map(int,input().split()))
#X1_list = [int(input()) for i in range(N)]
#X2_list = [list(map(int,input().split())) for i in range(N)]

'''
3 3 
8 6 5
'''
import sys
sys.setrecursionlimit(20000000)
def swap(i):
    #print(A_list)
    #print(i)
    if i == N-1:
        tmp = A_list[0]
        A_list[0] = A_list[i]
        A_list[i] = tmp
        return
    if A_list[i] >= A_list[i+1]:
        tmp = A_list[0]
        A_list[0] = A_list[i]
        A_list[i] = tmp
        return
    else:
        swap(i+1)

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

Submission status: Wrong Answer

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

for i in range(n):
  if m == 0:
    break
  if max(a) == 2:
    break
  for _ in range(m):
    a[i] //= 2
    m -= 1
    if m == 0:
      break
    if a[i] <= 2:
      break

if m != 0:
  for _ in range(m):
    a[a.index(max(a))] //= 2

print(sum(a))

Submission status: Wrong Answer

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

for i in range(m):
    a[0] = a[0] // 2
    a.sort(reverse = True)

print(sum(a))

Submission status: Wrong Answer

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

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

a.sort()

if(n > m):
    ax = a[n-m:]
    ass = a[:n-m-1]
    for j in range(m):
    
        ax[-1] = ax[-1] // 2 
    
    print(sum(ass)+sum(ax))
else:
    for j in range(m):
        a[-1] = a[-1] // 2 
    print(sum(a))

Submission status: Wrong Answer

Solution code:
ip = lambda : map(int, input().split())
# ##############
N,M = ip()
A = list(ip())
am = {}
for i in A:
    am[i] = am.get(i,0) + 1

while M>0:
    print(am)
    ix = max(am.keys())
    if am[ix] <= M:
        M -= am[ix]
        am[ix//2] = am.get(ix//2,0) + am[ix]
        if ix!=0: am.pop(ix)
        else: break
    else :
        am[ix//2] = am.get(ix//2,0) + M
        am[ix] -= M
        break

ans = 0
for i,j in am.items():
    ans += i*j
print(ans)

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 and tempM > 0:
        y = round(M * (a/sumA))
        sumP += math.floor(a / (2**y))
        tempM -= y
    elif M > 1 and tempM == 0:
        sumP += a
print(sumP)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
a = list(map(lambda x: -int(x), input().split()))
import heapq
import math
value = -sum(a)
heapq.heapify(a)

for i in range(m):
  use = heapq.heappop(a)
  value += math.floor(use/2)
  heapq.heappush(a, math.ceil(use/2))
  
print(use)

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])
		return tmp[:idx-1] + [x[0]] + tmp[idx-1:]

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:
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[n] = A[n] // (2**Y)
        remainM = remainM - Y
        n += 1
        if remainM <= 0:
            break
    print(np.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))
  print(ans)
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 = list(map(int,input().split()))

a.sort()
ax = a[n-m:]
ass = a[:n-m-1]
for j in range(m):
    
    ax[-1] = ax[-1] // 2 
    
print(sum(ass)+sum(ax))

Submission status: Wrong Answer

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

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

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

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

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
A = sorted(list(map(int, input().split())), reverse=True)
A.append(1e-5)
ret = 0
judge = True
for i in range(N):
    judge = True
    j = 0
    tmp = A[i]
    for j in range(1, M+1):
        now = tmp - tmp // 2
        tmp //= 2
        nxt = A[i+1] - (A[i+1] - A[i+1]//2)
        if now <= nxt:
            M -= j
            ret += tmp
            judge = False
            break
    if judge:
        M -= j
        if j > 0:
            ret += tmp
        else:
            ret += A[i]


print(ret)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
a = list(map(int, input().split()))
#a = list(reversed(sorted(a)))
ans = 0
#minV = 10**15
total = sum(a)

while True:
    if m <= 0:
        break
    maxV = max(a)
    total -= maxV // 2

#    a[0] = a[0] // 2
#    a = list(reversed(sorted(a)))
    m -= 1

ans = 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):
    if a[0] == 0:
        break
    a[0] = a[0] // 2
    a.sort()
print(sum(a))

Submission status: Wrong Answer

Solution code:
import math

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

half_time = int(math.log2(coupon))

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

if half_time<=len(prices):
  for i in range(len(prices)-1):
    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
else:
  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

print(sum(prices))

Submission status: Wrong Answer

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

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

sum = 0

for i in range(n-1):
  cnt = 0
  while (m - cnt > 0) and (ai[i] >= ai[i+1] // (2 ** cnt)):
    m -= 1
    ai[i] = ai[i] // 2
    cnt += 1

  sum += ai[i]
    
for i in range(m):
  ai[n-1] = ai[n-1] // 2
  
sum += ai[n-1]

# print(ai)
print(sum)

Submission status: Wrong Answer

Solution code:
import numpy as np

N, M, *A, = map(int, open(0).read().split())

np_A = np.array(A)
for _ in range(M):
    a = np_A.argmax()
    A[a] = A[a] // 2
print(sum(A))

Submission status: Wrong Answer

Solution code:
import math
n, m = map(int, input().split())
a = 0
p = list(map(int, input().split()))
i = sorted(p, reverse=True)
for x in i:
    old = 2 ** math.ceil(m / 2)
    m = m // 2
    a += x // old

print(a)

Submission status: Wrong Answer

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

    from collections import deque


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

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

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

    top = aa.popleft()

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


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

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

Submission status: Wrong Answer

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

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

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

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

print(sum(A))

Submission status: Wrong Answer

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

for i in range(M):
    A[0]=A[0]//2
    A=np.sort(A)[::-1]
sum=0
for i in range(N):
    sum+=A[i]

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import bisect

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)
  
print(sum(a))

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 = -1
idx = 0
memoR = 1

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]:
            if L[memoR] < L[idx]:
                memoR = idx
            idx = memoL
            memoL -= 1
        else:
            if L[memoL] < L[idx]:
                memoL = idx
            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:
n, m = list(map(int, input().split()))
a = list(map(int, input().split()))

for i in range(m):
    a.sort()
    a[-1] /= 2**1

print(int(sum(a)))

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
a = [int(i) for i in input().split()]
a.sort(reverse=True)
for t in range(m):
	b = a[0]//2
	del a[0]
	if len(a) == 0:
		a.append(b)
	elif b <= a[-1]:
		a.insert(-1, b)
	else:
		for s in range(n-1):
			if b >= a[s]:
				a.insert(s, b)
				break
print(sum(a))

Submission status: Wrong Answer

Solution code:
N,M=[int(thing) for thing in input().split(" ")]
A_list=[int(thing) for thing in input().split(" ")]

A_list.sort(reverse=True)
for aaaaa in range(M):
    A_list[0]=A_list[0]*0.5
    A_list.sort(reverse=True)
print(sum([thing//1 for thing in A_list]))

Submission status: Wrong Answer

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

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

for i in range(M):
    A[0] //= 2
    k = 0
    for k in range(1, N):
        if A[0] > A[k]:
            break
    A.insert(k, A[0])
    del A[0]
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()]
for i in range(M):
  l=A.index(max(A))
  A[l]//=1
print(sum(A))

Submission status: Wrong Answer

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

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

sum = 0

for i in range(n-1):
  cnt = 0
  while (m - cnt > 0) and (ai[i] > ai[i+1] // (2 ** cnt)):
    m -= 1
    ai[i] = ai[i] // 2
    cnt += 1

  sum += ai[i]
    
for i in range(m):
  ai[n-1] = ai[n-1] // 2
  
sum += ai[n-1]

# print(ai)
print(sum)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left

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

A.sort(reverse=True)
for i in range(M):
    A[0] = (A[0]) // (2)
    tmp = A.pop(0)
    k = bisect_left(A, tmp)
    A.insert(k - 1, tmp)

print(sum(A))

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
        i -= 1

print(sum(a))

Submission status: Wrong Answer

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

for _ in range(m):
    Amax = a.index(max(a))
    print(Amax)
    a[Amax] = a[Amax] // 2
    if sum(a) == 0:
        break    

print(sum(a))