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 = list(map(int,input().split()))
A = list(map(int,input().split()))
sum = sum(A)
num = 0
for i in range(M):
    B = max(A)
    num += B - B // 2
print(sum)

Submission status: Wrong Answer

Solution code:
N,M = list(map(int,input().split()))
A = list(map(int,input().split()))
sum = sum(A)
for i in range(M):
    B = max(A)
    sum = sum - B + B//2
print(sum)

Submission status: Wrong Answer

Solution code:
N,M = list(map(int,input().split()))
A = list(map(int,input().split()))
sum = sum(A)
for i in range(M):
    B = max(A)
    sum -= B//2
print(sum)

Submission status: Wrong Answer

Solution code:
n,m = map(int, input().split())
pri =[0]*n
dc  =[0]*n

pri = list(map(int, input().split()))
    
for i in range(m):
	newp = 0
	p1=0
	for j in range(n):
		if pri[j]//(2**dc[j]) >newp:
			newp=pri[j]//(2**dc[j])
			p1=j
	dc[p1]=dc[p1]+1
#	print(p1,pri[p1]//(2**dc[p1]
total = 0
for i in range(n):
	total = total + pri[j]//(2**dc[j])
print(total)

Submission status: Wrong Answer

Solution code:
import heapq
import math
N,M=map(int,input().split())
A=list(map(int,input().split()))
A.sort()
logof2=[0]*N
mi=0
buf=0
#print(A)
for i in range(N):
    logof2[i]=-math.log2(A[i])
#print(logof2)
heapq.heapify(logof2)
for i in range(M):
    buf=heapq.heappop(logof2)
    buf=buf+1
    heapq.heappush(logof2,buf)
    #print(logof2)
for i in range(N):
    mi=mi+math.floor(pow(2,-logof2[i]))

print(mi)

Submission status: Wrong Answer

Solution code:
import heapq
import math
N,M=map(int,input().split())
A=list(map(int,input().split()))
A.sort()
logof2=[0]*N
mi=0
buf=0
#print(A)
for i in range(N):
    logof2[i]=-math.log(A[i],2)
#print(logof2)
heapq.heapify(logof2)
for i in range(M):
    buf=heapq.heappop(logof2)
    buf=buf+1
    heapq.heappush(logof2,buf)
    #print(logof2)
for i in range(N):
    mi=mi+math.floor(pow(2,-logof2[i]))

print(mi)

Submission status: Wrong Answer

Solution code:
import bisect
import math
N,M=map(int,input().split())
A=list(map(int,input().split()))
A.sort()
logof2=[0]*N
mi=0
buf=0
#print(A)
for i in range(N):
    logof2[i]=math.log(A[i],2)
#print(logof2)
for i in range(M):
    if logof2[N-1]<0:
        break
    else:
        buf=logof2.pop(N-1)
        buf=buf-1
        bisect.insort(logof2,buf)

    #print(logof2)
for i in range(N):
    mi=mi+math.floor(pow(2,logof2[i]))

print(mi)

Submission status: Wrong Answer

Solution code:
import math
N,M=map(int,input().split())
A=list(map(int,input().split()))
A.sort(reverse=True)
logof2=[0]*N
mi=0
#print(A)
for i in range(N):
    logof2[i]=math.log(A[i],2)
#print(logof2)
for i in range(M):
    if logof2[0]<0:
        break
    else:
        logof2[0]=logof2[0]-1
        logof2.sort(reverse=True)
    #print(logof2)
for i in range(N):
    mi=mi+math.floor(pow(2,logof2[i]))

print(mi)

Submission status: Wrong Answer

Solution code:
import math
N,M=map(int,input().split())
A=list(map(int,input().split()))
A.sort(reverse=True)
logof2=[0]*N
mi=0
#print(A)
for i in range(N):
    logof2[i]=math.log2(A[i])
#print(logof2)
for i in range(M):
    if logof2[0]<0:
        break
    else:
        logof2[0]=logof2[0]-1
        logof2.sort(reverse=True)
    #print(logof2)
for i in range(N):
    mi=mi+math.floor(pow(2,logof2[i]))

print(mi)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
a = sorted([int(i) for i in input().split()])
ans = 0
while m > 0:
    a[-1] = a[-1]//2
    num = a[-1]
    a.pop()
    m-=1
    l,r = 0,n-1
    t=0
    while l+1<r:
        t = (l+r)//2
        if a[t] < num: l=t
        elif a[t] >= num: r=t
    a.insert(t,num)  
print(sum(a))

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    #from itertools import product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    n,m = map(int, input().split())
    a = list(map(int, input().split()))
    a.sort()
    while 1:
        a[-1] = a[-1] / 2
        m -= 1
        if m==0:
            res = 0
            for j in a:
                res += int(j)
            print(res)
            exit()
        p = bisect_right(a, a[-1])
        for i in range(p, n-1):
            a[i] = a[i] / 2
            m -= 1
            if m==0:
                res = 0
                for j in a:
                    res += int(j)
                print(res)
                exit()
        a.sort()



if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    #from itertools import product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

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



if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    #from itertools import product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    n,m = map(int, input().split())
    a = list(map(int, input().split()))
    a.sort()
    while 1:
        a[-1] = a[-1] // 2
        m -= 1
        p = bisect_right(a, a[-1])
        for i in range(p, n-1):
            if m==0:
                break
            a[i] = a[i] // 2
            m -= 1
        a.sort()
        if m==0:
            break
    print(sum(a))



if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import bisect

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

Ai.sort()
for _ in range(M):
    value = int(Ai.pop() / 2)
    bisect.insort(Ai, value)

sum(Ai)

Submission status: Wrong Answer

Solution code:
import bisect

n, m = map(int, input().split())
a = map(int, input().split())
a = sorted(a)
for i in range(m):
  a[-1] = int(a[-1] / 2)
  tmp = a[1:]
  p = bisect.bisect_left(tmp, a[0])
  a = tmp[:p] + [a[-1]] + tmp[p:]
print(sum(a))

Submission status: Wrong Answer

Solution code:
import bisect

n, m = map(int, input().split())
a = map(int, input().split())
a = sorted(a)[::-1]
for i in range(m):
  a[0] = int(a[0] / 2)
  p = bisect.bisect_left(a[1:], a[0])
  a = a[1:p] + [a[0]] + a[p:]
print(sum(a))

Submission status: Wrong Answer

Solution code:
import math

[n,m] = [int(x) for x in input().split(" ")]
an = [int(x) for x in input().split(" ")]
an.sort(reverse=True)

log2_an = [math.ceil(math.log2(x) + 1) for x in an]
max_log2 = log2_an[0]
rest_ticket = m

for i in range(max_log2):
    cnt = log2_an.count(log2_an[0])
    if(cnt <= rest_ticket):
        for j in range(cnt):
            an[j] = an[j] / 2
    else:
        for j in range(rest_ticket):
            an[j] = an[j] / 2
        break
    rest_ticket -= cnt
    an.sort(reverse=True)

discounted_an = [math.floor(x) for x in an]
print(sum(discounted_an))

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) :
  a[n-1] = a[n-1]//2
  b = a[0:n-1]
  index = bisect.bisect_right(b,a[n-1])

print(sum(a))

Submission status: Wrong Answer

Solution code:
import heapq 
h = []

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

start = heapq.heappop(h)
for i in range(M):
  start = heapq.heappushpop(h,start//2)
print(-(sum(h)+start))

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] = int(a[n-1]//2)
  a.sort()

res = 0
for i in range(n):
  res += i
  
print(res)

Submission status: Wrong Answer

Solution code:
from heapq import heappush, heappop, heapify
import numpy as np
N, M = map(int,input().split())
A = list(map(int,input().split()))
A = np.array(A)
A = -A
A = list(A)
for _ in range(M):
    heapify(A)
    s = heappop(A)
    heappush(A, -(-s // 2))
    print(s)
A = np.array(A)
print(-int(np.sum(A)))

Submission status: Wrong Answer

Solution code:
from heapq import heappush, heappop, heapify
import numpy as np
N, M = map(int,input().split())
A = list(map(int,input().split()))
A = np.array(A)
A = -A
A = list(A)
for _ in range(M):
    heapify(A)
    s = heappop(A)
    heappush(A, -(-s // 2))
    print(s)
A = np.array(A)
print(-int(np.sum(A)), A)

Submission status: Wrong Answer

Solution code:
from heapq import heappush, heappop
import numpy as np
N, M = map(int,input().split())
A = list(map(int,input().split()))
A = np.array(A)
A = -A
A = list(A)
for _ in range(M):
    s = heappop(A)
    heappush(A, -(-s // 2))
A = np.array(A)
print(-int(np.sum(A)))

Submission status: Wrong Answer

Solution code:
import math
N,M=map(int,input().split())
mylist=list(map(int,input().split()))


while M>0:
    mylist.sort(reverse=True)
    mylist[0]/=2
    M-=1
    
mylist=[math.floor(i) for i in mylist]
print(mylist)
print(sum(mylist))

Submission status: Wrong Answer

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

for _ in range(0, M, 1):
	A[0] >>= 1
	for i in range(1, len(A), 1):
		if A[i - 1] > A[i]:
			A[i], A[i - 1] = A[i - 1], A[i]
		else:
			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)

for _ in range(0, M, 1):
	A[0] >>= 1
	for i in range(1, len(A), 1):
		if A[i] < A[i - 1]:
			A[i], A[i - 1] = A[i - 1], A[i]
		else:
			break

print(sum(A))

Submission status: Wrong Answer

Solution code:
import numpy as np
n,m = map(int,input().split())
a = list(map(int,input().split()))
all = []
devide = []
money = 0
for i in range(n):
    s = [-1]*(m+1)
    s[0] = a[i]
    for j in range(m):
        k = a[i]//(2**(j+1))
        s[j+1] = k
    all.append(s)
for i in range(n):
    d = []
    for j in range(m):
        d.append(all[i][j]-all[i][j+1])
    devide.append(d)
res = [0]*n
for i in range(m):
    max_value = max(map(lambda x:x[0],devide))
    for j in range(m):
        if devide[j][0] == max_value:
            res[j] += 1
            devide[j] = devide[j][1:]
            break
for i in range(n):
    money += all[i][res[i]]
print(money)

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
a = [int(c) for c in input().split()]
a.sort()
def putmid():
	right = n
	left = 0
	mid = 0
	while right - left > 1:
		mid = (right + left) // 2
		if a[mid] <= a[-1]:
			left = mid
		else:
			right = mid
	a.insert(mid,a[-1])
	a.pop(-1)

for i in range(m):
	a[-1] = a[-1]//2
	putmid()
	
print(sum(a))

Submission status: Wrong Answer

Solution code:
from heapq import heapify, heappush, heappop
N, M = map(int, input().split())
A = list(map(int, input().split()))
A = list(map(lambda x: -x, A))
heapify(A)
print(A)
for i in range(M):
    mx = heappop(A)
    heappush(A, (-1)*(-mx//2))
A = list(map(lambda x: -x, 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.sort(reverse=True)
ans = 0
while True:
    for i in range(N):
        if M == 0:
            print(sum(A))
            exit()
        if i == 0:
            A[i] = A[i]//2
            M -= 1
        else:
            if A[i-1] >= A[i]:
                break
            else:
                A[i] = A[i]//2
                M -= 1

Submission status: Wrong Answer

Solution code:
import bisect
import heapq
n,m = map(int,input().split())
A = list(map(int,input().split()))
A = list(map(lambda x: x*(-1), A))


heapq.heapify(A)


for _ in range(m):
  a = heapq.heappop(A)//2
  heapq.heappush(A,a)
print(-sum(A))

Submission status: Wrong Answer

Solution code:
from fractions import gcd
from math import ceil,sqrt
a, b = map(int, input().split())

g = gcd(a,b)

s = set()
for i in range(2,ceil(sqrt(g))+1):
    while g % i == 0:
        g //= i
        s.add(i)
if g != 1:
    s.add(int(1e14))
#print(g)
#print(s)
print(len(s)+1)

Submission status: Wrong Answer

Solution code:


import heapq

n,m=map(int,input().split())
a=list(map(int,input().split()))
b=[-int(i) for i in a]

heapq.heapify(b)

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

print(-(sum(b)))

Submission status: Wrong Answer

Solution code:


import heapq

n,m=map(int,input().split())
a=list(map(int,input().split()))
b=[-int(i) for i in a]

heapq.heapify(b)

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

print(-sum(b))

Submission status: Wrong Answer

Solution code:


import heapq

n,m=map(int,input().split())
a=list(map(int,input().split()))
b=[-int(i) for i in a]

heapq.heapify(b)

for i in range(m):
    x=heapq.heappop(b)//2
    heapq.heappush(b,x)

print(-sum(b))

Submission status: Wrong Answer

Solution code:
from heapq import heapify, heappop, heappush

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

for i in range(n):
    a[i] *= -1
heapify(a)
print(a)
for i in range(m):
    maxa = heappop(a)
    heappush(a, -(-maxa//2))
print(a)
print(-(sum(a)))

Submission status: Wrong Answer

Solution code:
N, M = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
import bisect
cnt = 0
if N == 1:
    print(int(A[0]/(2**M)))
    exit()
else:
    while cnt < M:
        A[-1] /= 2
        if A[-1] < A[-2]:
            a = A[-1]
            del A[-1]
            bisect.insort_left(A, a)
            cnt += 1

ans = 0
for i in range(N):
    ans += int(A[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)

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

Submission status: Wrong Answer

Solution code:
import heapq

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

nums = [n * -1 for n in nums]
heapq.heapify(nums)

while M > 0:
    curr = heapq.heappop(nums)
    heapq.heappush(nums,curr//2)
    M -=1

print(-sum(nums))

Submission status: Wrong Answer

Solution code:
import heapq
n, m = map(int, input().split())
lst = list(map(lambda x:-1*int(x), input().split()))
heapq.heapify(lst)
for i in range(m):
  heapq.heappush(lst, -(-heapq.heappop(lst))//2)
print(-1*sum(lst))

Submission status: Wrong Answer

Solution code:
import heapq
n, m = map(int, input().split())
lst = list(map(lambda x:-1*int(x), input().split()))
heapq.heapify(lst)
for i in range(m):
  heapq.heappush(lst, heapq.heappop(lst)//2)
print(-1*sum(lst))

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(M):
  A[0] //= 2
  if N > 1:
    j = 0
    while A[j] < A[j+1]:
      A[j], A[j+1] = A[j+1], A[j]
      j += 1
      if j == N-2:
        break
#  print(A)
print(sum(A))

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
for _ in range(m):
  p = a.pop()//2
  up=n-1
  low=0
  while up-low > 1:
    nb = low+(up-low)//2
    if p >= a[nb]:
      low = nb
    else:
      up = nb
  a.insert(up, p)
print(sum(a))

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
for _ in range(m):
  p = a[n-1]//2
  up=n-1
  low=0
  while up-low == 1:
    nb = low+(up-low)//2
    if p <= a[nb]:
      up = nb
    else:
      low = nb
  a.insert(up, p)
print(sum(a[:n]))

Submission status: Wrong Answer

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

items = list(map(lambda x:int(x)*(-1), input().split()))
heapq.heapify(items)
             
for i in range(m):
    pop = heapq.heappop(items)
    heapq.heappush(items, pop//2)

print(-1*sum(items))

Submission status: Wrong Answer

Solution code:
import heapq
import math

def LI():
  return [int(s) for s in input().split()]

N,M = LI()
a = LI()
a = list(map(lambda x: x*(-1), a))  # 各要素を-1倍

heapq.heapify(a)

for i in range(M):
    x = (-1)*(abs(heapq.heappop(a))//2)
    print(x)
    heapq.heappush(a,x)

cost = 0
for i in range(N):
  x = heapq.heappop(a)
  cost+=abs(x)
  
print(cost)

Submission status: Wrong Answer

Solution code:
import heapq

def LI():
  return [int(s) for s in input().split()]

N,M = LI()
a = LI()
a = list(map(lambda x: x*(-1), a))  # 各要素を-1倍

heapq.heapify(a)

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

cost = 0
for i in range(N):
  x = heapq.heappop(a)
  cost+=abs(x)
  
print(cost)

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
A = list(map(int,input().split()))
import heapq
heapq.heapify(A)
for i in range(M):
    a = A.pop()
    a = a//2
    heapq.heappush(A,a)
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):
    a = A.pop()
    a = a//2
    A.append(a)
    A.sort()
ans = sum(A)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
A = list(map(int,input().split()))
for i in range(M):
    A[-1] //= 2
    A.sort()
print(sum(A))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
from heapq import heapify, heappop, heappush


def negative(str):
    return -1 * int(str)


def main():
    N, M = map(int, input().split(" "))
    A = list(map(negative, input().split(" ")))
    heapify(A)
    while M > 0:
        x = heappop(A)
        heappush(A, -1 * (-1 * x // 2))
        M -= 1
    print(sum(A))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n, m = (int(x) for x in input().split())
a = [int(x) for x in input().split()]
print(a)
for _ in range(m):
    idx = a.index(max(a))
    a[idx] //= 2
print(sum(a))

Submission status: Wrong Answer

Solution code:
from math import floor


def main():
    N, M = map(int, input().split(" "))
    A = list(map(int, input().split(" ")))
    A.sort(reverse=True)
    while M > 0:
        for i in range(0, N):
            if A[i] > 2 and M > 0:
                A[i] = floor(A[i] / 2)
                M -= 1
    print(sum(A))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from math import floor


def main():
    N, M = map(int, input().split(" "))
    A = list(map(int, input().split(" ")))
    A.sort(reverse=True)
    print(A)
    while M > 0:
        for i in range(0, N):
            if A[i] > 2 and M > 0:
                A[i] = floor(A[i] / 2)
                M -= 1
        print(A)
    print(sum(A))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import heapq
N, M = map(int, input().split())
A = list(map(int, input().split()))
A = list(map(lambda x: -1 * x, A))
# A.sort(reverse=True)
heapq.heapify(A)
for i in range(M):
    tmp = heapq.heappop(A)
    heapq.heappush(A, tmp // 2)
print(-sum(A))

Submission status: Wrong Answer

Solution code:
import heapq
def main():
    n,m=map(int,input().split())
    a=list(map(int,input().split()))
    for i,aa in enumerate(a):
        a[i] = -1 * aa
    heapq.heapify(a)
    for i in range(m):
        tmp = heapq.heappop(a) // 2
        heapq.heappush(a,tmp)
    print(sum(a) * (-1))
if __name__=='__main__':
    main()

Submission status: Wrong Answer

Solution code:
#Priority Queueを使った解法
import heapq

N,M = map(int,input().split())
A = list(map(lambda x:(-1)*int(x),input().split()))

heapq.heapify(A)

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

print(-sum(A))

Submission status: Wrong Answer

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

A.sort()
l = -1
r = A[-1] + 1


while r - l > 1:
    m = (r + l) // 2
    t = 0
    mc = 0
    a = 0
    for i in range(N):
        s = A[i]
        while m < s:
            s //= 2
            mc += 1
        a += s
    if mc <= M:
        r = m
        ans = a - (M - mc) * (m // 2)
    else:
        l = m 
            
print(ans)

Submission status: Wrong Answer

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

A.sort()
l = -1
r = A[-1] + 1


while r - l > 1:
    m = (r + l) // 2
    t = 0
    mc = 0
    a = 0
    for i in range(N):
        s = A[i]
        while m < s:
            s //= 2
            mc += 1
        a += s
    if mc <= M:
        r = m
        ans = a 
    else:
        l = m 
            
print(ans)

Submission status: Wrong Answer

Solution code:
#n = int(input())
#L = list(map(int, input().split()))
import math
import sys
import heapq
import fractions
L = list(map(int, input().split()))
A = list(map(int, input().split()))
heapq.heapify(A)
for i in range(L[1]):
    mx = heapq.heappop(A)
    heapq.heappush(A, mx//2)
print(sum(A))

Submission status: Wrong Answer

Solution code:
import heapq

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

B = []

for i in A:
    B.append(-i)

heapq.heapify(B)
print(*B)
for i in range(M):
    tmp = heapq.heappop(B)
    heapq.heappush(B,-1*(-tmp//2))

print(-sum(B))

Submission status: Wrong Answer

Solution code:
import heapq

Submission status: Wrong Answer

Solution code:
import heapq
from sys import stdin
n,m = map(int,stdin.readline().split())
*l, = map(lambda x:-int(x),stdin.readline().split())
heapq.heapify(l)
for i in [0]*m:
  a=heapq.heappop(l)
  heapq.heappush(l, a//2)
print(-(sum(l)))

Submission status: Wrong Answer

Solution code:
import heapq
n, m = map(int, input().split(' '))
a = []
for i in list(map(int, input().split(' '))):
    heapq.heappush(a,-i)

for _ in range(m):
    p = heapq.heappop(a)
    heapq.heappush(a, p//2)

print(-sum(a))

Submission status: Wrong Answer

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

else:
    for _ in range(m):
        p = heapq.heappop(a)
        heapq.heappush(a, int(p/2))

    print(-sum(a))

Submission status: Wrong Answer

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

else:
    for _ in range(m):
        p = heapq.heappop(a)
        heapq.heappush(a, p//2)

    print(-sum(a))

Submission status: Wrong Answer

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

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

else:
    for i in range(m):
        l = max(a)
        c = a.index(l)
        ans = ans - l + l//2
        a[c] = a[c]//2
print(ans)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
L=list(map(int,input().split()))
L.sort()
from collections import deque
Ld=deque(L)
A=[0]
Ad=deque(A)
for i in range(m):
    if Ld==deque([]):
        if Ad==deque([]):
            break
        else:
            if Ad[-1]!=0:
                x=Ad.pop()//2
                if x>=Ad[-1]:
                    Ad.append(x)
                else:
                    Ad.appendleft(x)
            else:
                break
    else:
        if Ld[-1] >=Ad[-1]:
            x=Ld.pop()//2
            if x>=Ad[-1]:
                Ad.append(x)
            else:
                Ad.appendleft(x)
        else:
            x=Ad.pop()//2
            if x>=Ad[-1]:
                Ad.append(x)
            else:
                Ad.appendleft(x)
print(sum(list(Ld))+sum(list(Ad)))

Submission status: Wrong Answer

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

def tc(num):
  c = 1
  while True:
    answer = num // 2 ** c
    if answer == 1:
      return c -1
    c += 1

def use(ticket_count, usable):
  if ticket_count - usable < 0:
    return ticket_count
  return usable

tickets = m
sa = list(sorted(a, reverse=True))
for index, ai in enumerate(sa[:]):
  use_ticket = tc(ai)
  if tickets > 0:
    usecount = use(tickets, use_ticket)
    tickets -= usecount
    sa[index] = ai // (2 ** usecount)
  if tickets == 0:
    break


print(sum(sa))

Submission status: Wrong Answer

Solution code:
import math
import heapq

N,M = map(int,input().split())
A = [0]*N
A = list(map(lambda x: int(x)*(-1),input().split()))
if (N == 1):
    print(A[0]//(2**M))
else:
    """
    while (M != 0):
        A.sort(reverse=True)
        y = min(math.floor(log2(A[0]/A[1])+1),M)
        A[0] //= 2**y
        M -= y
    """
    """
    A.sort(reverse=True)
    for i in range(N):
        y = min(A[i] // 2,M)
        A[i] //= 2**y
        M -= y
        if (M <= 0):
            break
    """
    heapq.heapify(A)

    for i in range(M):
        m = heapq.heappop(A) * -1
        heapq.heappush(A,(m//2 * -1))

    print(-sum(A))

Submission status: Wrong Answer

Solution code:
def main():
    n, m = map(int, input().split())
    a_list = list(map(int, input().split()))

    for _ in range(m):
        a_list[a_list.index(max(a_list))] /= 2

    print(sum(a_list))


if __name__ == '__main__':
    main()

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[-1] = int(max(a)/2)
        a.sort()

sum(a)

Submission status: Wrong Answer

Solution code:
import heapq

n, m = map(int, input().split())
a = list(int(i)*(-1) for i in input().split())

print(a)
heapq.heapify(a)
for i in range(m):
    max = heapq.heappop(a)
    heapq.heappush(a,int(max/2))

print(sum(a) * (-1))

Submission status: Wrong Answer

Solution code:
import heapq as hq
n,m=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(lambda x: x*(-1),A))
hq.heapify(B)
for i in range(m):
  x=hq.heappop(B)
  hq.heappush(B,x//2)

print(sum(B)*(-1))

Submission status: Wrong Answer

Solution code:
import heapq as hq
n,m=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(lambda x: x*(-1),A))
hq.heapify(B)
for i in range(m):
  x=hq.heappop(B)
  hq.heappush(B,x//2)

print(sum(B))

Submission status: Wrong Answer

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

while M != 0:
    m = max(A)
    A.remove(m)
    A.add(m//2)
    M -= 1

print(sum(A))

Submission status: Wrong Answer

Solution code:
import heapq

N , M = map(int,input().split())
A = [-int(i) for i in input().split()]

heapq.heapify(A)
for _ in range(M):
    a = heapq.heappop(A) >> 1
    heapq.heappush(A,a)
print(-sum(A))

Submission status: Wrong Answer

Solution code:
import heapq

n,m=map(int,input().split())
a=list(map(int,input().split()))
a=list(map(lambda x: int(x)*(-1) , a))
heapq.heapify(a)
for i in range(m):
  x=heapq.heappop(a)*(-1)
  heapq.heappush(a,-1*(x//2))
print(sum(a))

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
l_ = list(map(int, input().split()))
l = [(-1)*l_[i] for i in range(n)]

import heapq
heapq.heapify(l)

for i in range(n):
  x = (-1)*heapq.heappop(l)
  heapq.heappush(l, (x//2)*(-1))

print(sum(l)*(-1))

Submission status: Wrong Answer

Solution code:
import heapq
n, m = map(int, input().split())
li = [-int(x) for x in input().split()]
heapq.heapify(li)
for i in range(n):
  a = heapq.heappop(li)
  heapq.heappush(li, a/2)
print(-sum(int(x) for x in li))

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
A=sorted(list(map(int,input().split())))
for i in range(M):
  if A[len(A)-1]<A[len(A)-2]:
      a=A[len(A)-1]
      A[len(A)-1]=A[len(A)-2]
      A[len(A)-2]=a
  A[len(A)-1]=A[len(A)-1]//2
print(sum(A))

Submission status: Wrong Answer

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

import heapq

pq = [-1 * x for x in nums]
heapq.heapify(pq)
for _ in range(M):
  x = -heapq.heappop(pq)
  heapq.heappush(pq, -x//2)

ans = 0
for i in range(N):
    t = heapq.heappop(pq)
    t = t * (-1)
    ans = ans + t
print(ans)

Submission status: Wrong Answer

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

import heapq

pq = [-1 * x for x in nums]
heapq.heapify(pq)
for _ in range(M):
  x = -heapq.heappop(pq)
  heapq.heappush(pq, -x/2)

ans = 0
for i in range(N):
    t = heapq.heappop(pq)
    t = t * (-1)
    ans = ans + t
print(ans)

Submission status: Wrong Answer

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

import heapq

pq = [-1 * x for x in nums]
heapq.heapify(pq)
for _ in range(M):
  x = -heapq.heappop(pq)
  heapq.heappush(pq, -x/2)

print(-sum(pq))