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

Solution (Python):
import sys
from collections import Counter

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.buffer.readline


def upsqrt(x):
    k = x ** 0.5
    res = 1
    while res < k:
        res <<= 1
    return res


def botsqrt(x):
    k = x ** 0.5
    res = 1
    while res <= k:
        res <<= 1
    return res >> 1


class VanEmdeBoasTree:
    def __init__(self, size):
        self.universe_size = 1
        while self.universe_size < size:
            self.universe_size <<= 1
        self.minimum = -1
        self.maximum = -1
        self.summary = None
        self.cluster = {}
    
    def __high(self, x):
        return x // botsqrt(self.universe_size)
    
    def __low(self, x):
        return x % botsqrt(self.universe_size)
    
    def __generate_index(self, x, y):
        return x * botsqrt(self.universe_size) + y
    
    def min(self):
        return self.minimum
    
    def max(self):
        return self.maximum
    
    def __empinsert(self, key):
        self.minimum = self.maximum = key
    
    def insert(self, key):
        if self.minimum == -1:
            self.__empinsert(key)
        else:
            if key < self.minimum:
                self.minimum, key = key, self.minimum
            if 2 < self.universe_size:
                if self.__high(key) not in self.cluster:
                    self.cluster[self.__high(key)] = VanEmdeBoasTree(botsqrt(self.universe_size))
                    if self.summary is None:
                        self.summary = VanEmdeBoasTree(upsqrt(self.universe_size))
                    self.summary.insert(self.__high(key))
                    self.cluster[self.__high(key)].__empinsert(self.__low(key))
                else:
                    self.cluster[self.__high(key)].insert(self.__low(key))
            if self.maximum < key:
                self.maximum = key
    
    def is_member(self, key):
        if self.minimum == key or self.maximum == key:
            return True
        elif self.universe_size == 2:
            return False
        else:
            if self.__high(key) in self.cluster:
                return self.cluster[self.__high(key)].is_member(self.__low(key))
            else:
                return False
    
    def successor(self, key):
        if self.universe_size == 2:
            if key == 0 and self.maximum == 1:
                return 1
            else:
                return -1
        elif self.minimum != -1 and key < self.minimum:
            return self.minimum
        else:
            max_incluster = -1
            if self.__high(key) in self.cluster:
                max_incluster = self.cluster[self.__high(key)].max()
            if max_incluster != -1 and self.__low(key) < max_incluster:
                offset = self.cluster[self.__high(key)].successor(self.__low(key))
                return self.__generate_index(self.__high(key), offset)
            else:
                succ_cluster = self.summary.successor(self.__high(key))
                if succ_cluster == -1:
                    return -1
                else:
                    offset = self.cluster[succ_cluster].min()
                    return self.__generate_index(succ_cluster, offset)
    
    def predecessor(self, key):
        if self.universe_size == 2:
            if key == 1 and self.minimum == 0:
                return 0
            else:
                return -1
        elif self.maximum != -1 and self.maximum < key:
            return self.maximum
        else:
            min_incluster = -1
            if self.__high(key) in self.cluster:
                min_incluster = self.cluster[self.__high(key)].min()
            if min_incluster != -1 and min_incluster < self.__low(key):
                offset = self.cluster[self.__high(key)].predecessor(self.__low(key))
                return self.__generate_index(self.__high(key), offset)
            else:
                pred_cluster = -1
                if self.summary is not None:
                    pred_cluster = self.summary.predecessor(self.__high(key))
                if pred_cluster == -1:
                    if self.minimum != -1 and self.minimum < key:
                        return self.minimum
                    else:
                        return -1
                else:
                    offset = self.cluster[pred_cluster].max()
                    return self.__generate_index(pred_cluster, offset)
    
    def delete(self, key):
        if self.minimum == self.maximum:
            self.minimum = self.maximum = -1
            return True
        elif self.universe_size == 2:
            if key == 0:
                self.minimum = 1
            else:
                self.minimum = 0
            self.maximum = self.minimum
            return False
        else:
            if key == self.minimum:
                first_cluster = self.summary.min()
                key = self.__generate_index(first_cluster, self.cluster[first_cluster].min())
                self.minimum = key
            flg0 = self.cluster[self.__high(key)].delete(self.__low(key))
            if flg0:
                del self.cluster[self.__high(key)]
                flg1 = self.summary.delete(self.__high(key))
                if key == self.maximum:
                    if flg1:
                        self.maximum = self.minimum
                    else:
                        max_insummary = self.summary.max()
                        self.maximum = self.__generate_index(max_insummary, self.cluster[max_insummary].max())
            elif key == self.maximum:
                self.maximum = self.__generate_index(self.__high(key), self.cluster[self.__high(key)].max())


def solve():
    N, M = map(int, rl().split())
    A = list(map(int, rl().split()))
    
    veb = VanEmdeBoasTree(10 ** 9)
    for ai in A:
        veb.insert(ai)
    
    counter = Counter(A)
    for _ in range(M):
        maximum = veb.max()
        counter[maximum] -= 1
        if counter[maximum] == 0:
            veb.delete(maximum)
        if counter[maximum // 2] == 0:
            veb.insert(maximum // 2)
        counter[maximum // 2] += 1
    
    ans = 0
    for key, val in counter.items():
        ans += key * val
    print(ans)


if __name__ == '__main__':
    solve()

Solution (Python):
import sys
from collections import Counter

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def upsqrt(x):
    k = x ** 0.5
    res = 1
    while res < k:
        res <<= 1
    return res


def botsqrt(x):
    k = x ** 0.5
    res = 1
    while res <= k:
        res <<= 1
    return res >> 1


class VanEmdeBoasTree:
    def __init__(self, size):
        self.universe_size = 1
        while self.universe_size < size:
            self.universe_size <<= 1
        self.minimum = -1
        self.maximum = -1
        self.summary = None
        self.cluster = {}
    
    def __high(self, x):
        return x // botsqrt(self.universe_size)
    
    def __low(self, x):
        return x % botsqrt(self.universe_size)
    
    def __generate_index(self, x, y):
        return x * botsqrt(self.universe_size) + y
    
    def min(self):
        return self.minimum
    
    def max(self):
        return self.maximum
    
    def __empinsert(self, key):
        self.minimum = self.maximum = key
    
    def insert(self, key):
        if self.minimum == -1:
            self.__empinsert(key)
        else:
            if key < self.minimum:
                self.minimum, key = key, self.minimum
            if 2 < self.universe_size:
                if self.__high(key) not in self.cluster:
                    self.cluster[self.__high(key)] = VanEmdeBoasTree(botsqrt(self.universe_size))
                    if self.summary is None:
                        self.summary = VanEmdeBoasTree(upsqrt(self.universe_size))
                    self.summary.insert(self.__high(key))
                    self.cluster[self.__high(key)].__empinsert(self.__low(key))
                else:
                    self.cluster[self.__high(key)].insert(self.__low(key))
            if self.maximum < key:
                self.maximum = key
    
    def is_member(self, key):
        if self.minimum == key or self.maximum == key:
            return True
        elif self.universe_size == 2:
            return False
        else:
            if self.__high(key) in self.cluster:
                return self.cluster[self.__high(key)].is_member(self.__low(key))
            else:
                return False
    
    def successor(self, key):
        if self.universe_size == 2:
            if key == 0 and self.maximum == 1:
                return 1
            else:
                return -1
        elif self.minimum != -1 and key < self.minimum:
            return self.minimum
        else:
            max_incluster = -1
            if self.__high(key) in self.cluster:
                max_incluster = self.cluster[self.__high(key)].max()
            if max_incluster != -1 and self.__low(key) < max_incluster:
                offset = self.cluster[self.__high(key)].successor(self.__low(key))
                return self.__generate_index(self.__high(key), offset)
            else:
                succ_cluster = -1
                if self.summary is not None:
                    succ_cluster = self.summary.successor(self.__high(key))
                if succ_cluster == -1:
                    return -1
                else:
                    offset = self.cluster[succ_cluster].min()
                    return self.__generate_index(succ_cluster, offset)
    
    def predecessor(self, key):
        if self.universe_size == 2:
            if key == 1 and self.minimum == 0:
                return 0
            else:
                return -1
        elif self.maximum != -1 and self.maximum < key:
            return self.maximum
        else:
            min_incluster = -1
            if self.__high(key) in self.cluster:
                min_incluster = self.cluster[self.__high(key)].min()
            if min_incluster != -1 and min_incluster < self.__low(key):
                offset = self.cluster[self.__high(key)].predecessor(self.__low(key))
                return self.__generate_index(self.__high(key), offset)
            else:
                pred_cluster = -1
                if self.summary is not None:
                    pred_cluster = self.summary.predecessor(self.__high(key))
                if pred_cluster == -1:
                    if self.minimum != -1 and self.minimum < key:
                        return self.minimum
                    else:
                        return -1
                else:
                    offset = self.cluster[pred_cluster].max()
                    return self.__generate_index(pred_cluster, offset)
    
    def delete(self, key):
        if self.minimum == self.maximum:
            self.minimum = self.maximum = -1
            return True
        elif self.universe_size == 2:
            if key == 0:
                self.minimum = 1
            else:
                self.minimum = 0
            self.maximum = self.minimum
            return False
        else:
            if key == self.minimum:
                first_cluster = self.summary.min()
                key = self.__generate_index(first_cluster, self.cluster[first_cluster].min())
                self.minimum = key
            flg0 = self.cluster[self.__high(key)].delete(self.__low(key))
            if flg0:
                del self.cluster[self.__high(key)]
                flg1 = self.summary.delete(self.__high(key))
                if key == self.maximum:
                    if flg1:
                        self.maximum = self.minimum
                    else:
                        max_insummary = self.summary.max()
                        self.maximum = self.__generate_index(max_insummary, self.cluster[max_insummary].max())
            elif key == self.maximum:
                self.maximum = self.__generate_index(self.__high(key), self.cluster[self.__high(key)].max())


def solve():
    N, M = map(int, rl().split())
    A = list(map(int, rl().split()))
    
    veb = VanEmdeBoasTree(10 ** 9)
    for ai in A:
        veb.insert(ai)
    
    counter = Counter(A)
    for _ in range(M):
        maximum = veb.max()
        counter[maximum] -= 1
        if counter[maximum] == 0:
            veb.delete(maximum)
        if counter[maximum // 2] == 0:
            veb.insert(maximum // 2)
        counter[maximum // 2] += 1
    
    val = veb.max()
    ans = val * counter[val]
    for _ in range(N - 1):
        val = veb.predecessor(val)
        ans += val * counter[val]
    print(ans)


if __name__ == '__main__':
    solve()

Solution (Python):
import sys
from collections import Counter

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def upsqrt(x):
    k = x ** 0.5
    res = 1
    while res < k:
        res <<= 1
    return res


def botsqrt(x):
    k = x ** 0.5
    res = 1
    while res <= k:
        res <<= 1
    return res >> 1


class VanEmdeBoasTree:
    def __init__(self, size):
        self.universe_size = 1
        while self.universe_size < size:
            self.universe_size <<= 1
        self.minimum = -1
        self.maximum = -1
        self.summary = None
        self.cluster = {}
    
    def __high(self, x):
        return x // botsqrt(self.universe_size)
    
    def __low(self, x):
        return x % botsqrt(self.universe_size)
    
    def __generate_index(self, x, y):
        return x * botsqrt(self.universe_size) + y
    
    def min(self):
        return self.minimum
    
    def max(self):
        return self.maximum
    
    def __empinsert(self, key):
        self.minimum = self.maximum = key
    
    def insert(self, key):
        if self.minimum == -1:
            self.__empinsert(key)
        else:
            if key < self.minimum:
                self.minimum, key = key, self.minimum
            if 2 < self.universe_size:
                if self.__high(key) not in self.cluster:
                    self.cluster[self.__high(key)] = VanEmdeBoasTree(botsqrt(self.universe_size))
                    if self.summary is None:
                        self.summary = VanEmdeBoasTree(upsqrt(self.universe_size))
                    self.summary.insert(self.__high(key))
                    self.cluster[self.__high(key)].__empinsert(self.__low(key))
                else:
                    self.cluster[self.__high(key)].insert(self.__low(key))
            if self.maximum < key:
                self.maximum = key
    
    def is_member(self, key):
        if self.minimum == key or self.maximum == key:
            return True
        elif self.universe_size == 2:
            return False
        else:
            if self.__high(key) in self.cluster:
                return self.cluster[self.__high(key)].is_member(self.__low(key))
            else:
                return False
    
    def successor(self, key):
        if self.universe_size == 2:
            if key == 0 and self.maximum == 1:
                return 1
            else:
                return -1
        elif self.minimum != -1 and key < self.minimum:
            return self.minimum
        else:
            max_incluster = -1
            if self.__high(key) in self.cluster:
                max_incluster = self.cluster[self.__high(key)].max()
            if max_incluster != -1 and self.__low(key) < max_incluster:
                offset = self.cluster[self.__high(key)].successor(self.__low(key))
                return self.__generate_index(self.__high(key), offset)
            else:
                succ_cluster = self.summary.successor(self.__high(key))
                if succ_cluster == -1:
                    return -1
                else:
                    offset = self.cluster[succ_cluster].min()
                    return self.__generate_index(succ_cluster, offset)
    
    def predecessor(self, key):
        if self.universe_size == 2:
            if key == 1 and self.minimum == 0:
                return 0
            else:
                return -1
        elif self.maximum != -1 and self.maximum < key:
            return self.maximum
        else:
            min_incluster = -1
            if self.__high(key) in self.cluster:
                min_incluster = self.cluster[self.__high(key)].min()
            if min_incluster != -1 and min_incluster < self.__low(key):
                offset = self.cluster[self.__high(key)].predecessor(self.__low(key))
                return self.__generate_index(self.__high(key), offset)
            else:
                pred_cluster = -1
                if self.summary is not None:
                    pred_cluster = self.summary.predecessor(self.__high(key))
                if pred_cluster == -1:
                    if self.minimum != -1 and self.minimum < key:
                        return self.minimum
                    else:
                        return -1
                else:
                    offset = self.cluster[pred_cluster].max()
                    return self.__generate_index(pred_cluster, offset)
    
    def delete(self, key):
        if self.minimum == self.maximum:
            self.minimum = self.maximum = -1
            return True
        elif self.universe_size == 2:
            if key == 0:
                self.minimum = 1
            else:
                self.minimum = 0
            self.maximum = self.minimum
            return False
        else:
            if key == self.minimum:
                first_cluster = self.summary.min()
                key = self.__generate_index(first_cluster, self.cluster[first_cluster].min())
                self.minimum = key
            flg0 = self.cluster[self.__high(key)].delete(self.__low(key))
            if flg0:
                del self.cluster[self.__high(key)]
                flg1 = self.summary.delete(self.__high(key))
                if key == self.maximum:
                    if flg1:
                        self.maximum = self.minimum
                    else:
                        max_insummary = self.summary.max()
                        self.maximum = self.__generate_index(max_insummary, self.cluster[max_insummary].max())
            elif key == self.maximum:
                self.maximum = self.__generate_index(self.__high(key), self.cluster[self.__high(key)].max())


def solve():
    N, M = map(int, rl().split())
    A = list(map(int, rl().split()))
    
    veb = VanEmdeBoasTree(10 ** 9)
    for ai in A:
        veb.insert(ai)
    
    counter = Counter(A)
    for _ in range(M):
        maximum = veb.max()
        counter[maximum] -= 1
        if counter[maximum] == 0:
            veb.delete(maximum)
        if counter[maximum // 2] == 0:
            veb.insert(maximum // 2)
        counter[maximum // 2] += 1
    
    ans = 0
    for key, val in counter.items():
        ans += key * val
    print(ans)


if __name__ == '__main__':
    solve()

Solution (Python):
import heapq
import math
from heapq import heappop
n,m = map(int,input().split())
A = list(map(lambda x:-int(x),input().split()))
heapq.heapify(A)

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

print(-sum(A))

Solution (Python):
from math import ceil,floor,comb,factorial,gcd,pow,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n, m = MAP()
a = list(map(lambda x:int(x)*(-1), input().split()))

heapify(a)
while m > 0:
    m -= 1
    heappush(a, (-1)*(-heappop(a)//2))
print(-sum(a))

Solution (Python):
import heapq
import math

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):
    tmp = heapq.heappop(A)*(-1)
    heapq.heappush(A, (tmp/2)*(-1))
ans = 0
for _ in range(N):
    ans += math.floor(heapq.heappop(A)*(-1))
print(ans)

Solution (Python):

import math




n, m = map(int, input().split(' '))
a = list(map(lambda x: int(x) * (-1), input().split(' ')))




import heapq

q_a = heapq.heapify(a)

for m in range(m):
    x = heapq.heappop(a) * (-1)
    heapq.heappush(a, (x // 2) * (-1))

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

Solution (Python):
import sys
input = sys.stdin.buffer.readline
from math import log

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

table = [[0]*(int(log(a[-1],2))+2) for i in range(n)]

for i in range(n):
    for y in range(int(log(a[-1],2))+2):
        table[i][y] = a[i]//pow(2,y)
        if a[i]//pow(2,y) == 0:
            break

s_table = [[0]*(int(log(a[-1],2))+2) for i in range(n)]
for i in range(n):
    s_table[i][0] = table[i][0]

import heapq
hq = []
heapq.heapify(hq)
h_push = heapq.heappush
h_pop = heapq.heappop

for i in range(n):
    for y in range(1,int(log(a[-1],2))+2):
        s_table[i][y] = table[i][y]-table[i][y-1]
        h_push(hq,table[i][y]-table[i][y-1])
        if table[i][y]-table[i][y-1] == -1:
            break


ans = sum(a)

for i in range(m):
    if not hq:
        print(0)
        exit()
    ans += h_pop(hq)
    
print(ans)

Solution (Python):
from collections import deque

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





A.sort()


dp=deque([])

for m in range(M):
    if len(dp)==0:
        tmp=A.pop()
    elif len(A)==0:
        tmp=dp.popleft()
    else:
        if A[-1]>=dp[0]:
            tmp=A.pop()
        else:
            tmp=dp.popleft()
    dp.append(tmp//2)
print(sum(A)+sum(dp))

Solution (Python):

from heapq import heapify, heappop, heappush


def main():
    _, M = map(int, input().split())
    A = [-i for i in map(int, input().split())]
    heapify(A)

    discount = lambda: heappush(A, -(-heappop(A) // 2))
    for _ in range(M):
        discount()

    print(-sum(A))


if __name__ == "__main__":
    main()

Solution (Python):

from heapq import heapify, heappop, heappush


def main():
    _, M = map(int, input().split())
    A = [-i for i in map(int, input().split())]
    heapify(A)

    heappop_max = lambda heap: -heappop(heap)
    heappush_max = lambda heap, x: heappush(heap, -x)
    discount = lambda: heappush_max(A, heappop_max(A) // 2)

    for _ in range(M):
        discount()
    print(-sum(A))


if __name__ == "__main__":
    main()

Solution (Python):
import heapq

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

heapq.heapify(A)
for _ in range(M):
  heapq.heappush(A, (-((-heapq.heappop(A))//2)))
print(-sum(A))

Solution (Python):
import sys
input=sys.stdin.readline
from decimal import Decimal
from bisect import bisect
n,m=map(int,input().split())
lst=sorted(map(Decimal, input().split()))

while m>0:
    p=lst[-1]
    index=bisect(lst,p/2)
    for i in range(n-1,index-1,-1):
        if m>0:
            lst[i]=lst[i]/2
            m-=1
    lst=sorted(lst)
    if lst[-1]<1:
        break

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

Solution (Python):
from decimal import Decimal
from bisect import bisect
n,m=map(int,input().split())
lst=sorted(map(Decimal, input().split()))

while m>0:
    p=lst[-1]
    index=bisect(lst,p/2)
    for i in range(n-1,index-1,-1):
        if m>0:
            lst[i]=lst[i]/2
            m-=1
    lst=sorted(lst)
    if lst[-1]<1:
        break

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

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

A = list(map(lambda x: -1*int(x),input().split()))
import heapq
que = heapq.heapify(A)

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

Solution (Python):
import heapq
n,m = map(int, input().split())
al = list(map(int, input().split()))
al = [(-1)*a for a in al]
al.sort()

for _ in range(m):
    poped = heapq.heappop(al)
    heapq.heappush(al, (poped*(-1)//2)*(-1))

print(sum(al)*(-1))

Solution (Python):
import heapq

n, m = map(int, input().split())
alst = list(map(int, input().split()))
heap = [-1 * num for num in alst]
ans = sum(alst)
heapq.heapify(heap)

num = heapq.heappop(heap)
for _ in range(m):
    num *= -1
    tmp = num // 2
    ans -= num - tmp
    tmp *= -1
    num = heapq.heappushpop(heap, tmp)
print(ans)

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

Solution (Python):
n,m = map(int,input().split())
a = list(map(int,input().split()))
import heapq
q = [0]*n
for i in range(n):
    q[i] = -a[i]
heapq.heapify(q) 
for i in range(m):
    x = heapq.heappop(q) 
    heapq.heappush(q,-(-x//2))
ans = 0
for i in range(n):
    x = heapq.heappop(q)
    ans += x
print(-ans)

Solution (Python):






import heapq





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





heapq.heapify(A)
for m in range(M):
    tmp = heapq.heappop(A)
    heapq.heappush(A, -(-tmp//2))
print(-sum(A))

Solution (Python):
from heapq import heappop, heappush, heapify

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

for i in range(M):
    temp = int(heappop(A)/2)
    heappush(A, temp)

print(-sum(A))

Solution (Python):
import heapq

n, m = map(int, input().split())
a = [ -int(x) for x in input().split()]
heapq.heapify(a)

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

Solution (Python):






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

A = list(map(lambda x:-int(x),input().split()))
heapq.heapify(A) 

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

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

Solution (Python):
from heapq import heappush, heappop

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

q = []
for v in A:
    heappush(q, -v)
    
for _ in range(M):
    v = heappop(q)
    heappush(q, -((-v) // 2))
    
print(-sum(q))

Solution (Python):


import heapq

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


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

heapq.heapify(A)


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

print(abs(sum(A)))

Solution (Python):
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):
    tmp = heapq.heappop(A) * (-1)
    tmp //= 2
    heapq.heappush(A, tmp * (-1))

print(-sum(A))

Solution (Python):
import sys
from collections import deque
import itertools
from collections import deque
sys.setrecursionlimit(10 ** 9)
import heapq
import numpy as np




def input():
    return sys.stdin.readline().rstrip()


def main():
    N,M = map(int,input().split())
    A = list(map(lambda x: int(x)*-1,sys.stdin.read().split()))
    heapq.heapify(A)

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




    pass



if __name__ == "__main__":
    main()

Solution (Python):
import sys
import heapq

sys.setrecursionlimit(10**7)
input = sys.stdin.readline

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):
    tmp = heapq.heappop(a) * (-1)
    tmp //= 2
    heapq.heappush(a, tmp * (-1))

print(-sum(a))

Solution (Python):
from heapq import heapify, heappop, heappush
n, m = map(int, input().split())
list_A = list(map(int, input().split()))
for i in range(n):
    list_A[i] = (-1)*list_A[i]
heapify(list_A)
for _ in range(m):
    a = heappop(list_A)*(-1)
    a //= 2
    a *= (-1)
    heappush(list_A, a)

print((-1)*sum(list_A))

Solution (Python):
import heapq

n, m = map(int,input().split())
A = list(map(lambda x:-int(x),input().split()))

heapq.heapify(A)

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

Solution (Python):

from collections import defaultdict, deque, Counter, OrderedDict
import collections, heapq, itertools, bisect
import math, fractions
import sys, copy

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LIM(): return [-int(x) for x in sys.stdin.readline().split()]
def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline().rstrip())
def LS(): return [list(x) for x in sys.stdin.readline().split()]
def S(): return list(sys.stdin.readline().rstrip())
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
dire = [[1, 0], [0, 1], [-1, 0], [0, -1]]
dire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]]
MOD = 1000000007

def main():
    N, M = LI()
    A = LIM()
    heapq.heapify(A)
    for _ in range(M):
        x = -heapq.heappop(A)
        heapq.heappush(A, -(x // 2))
    print(-sum(A))

if __name__ == '__main__':
    main()

Solution (Python):
N,M = map(int,input().split())
A = list(map(int,input().split()))
import heapq
B = []
for a in A:
    B.append(-a)
heapq.heapify(B)
for i in range(M):
    a = heapq.heappop(B)
    a = (-a)//2
    a = -a
    heapq.heappush(B,a)
print(-sum(B))

Solution (Python):
import heapq as hq
n,m=map(int,input().split())
a=list(map(lambda x:-int(x),input().split()))
hq.heapify(a)
for i in range(m):v=-hq.heappop(a);hq.heappush(a,-(v//2))
print(-sum(a))

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

Solution (Python):
import heapq as hp

n,m=[int(x) for x in input().rstrip().split()]
a=[-int(x) for x in input().rstrip().split()]

hp.heapify(a)

for i in range(m):
  now=hp.heappop(a)
  hp.heappush(a,-(-now//2))
print(-sum(a))