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:
def get_answer(input_list):
    c_list = [int(v) for v in input_list[0].split(" ")]
    a = [int(v) for v in input_list[1].split(" ")]
    a = sorted(a, reverse=True)
    n = c_list[0]
    m = c_list[1]

    """
    for i in range(m):
        index = a.index(max(a))
        v = int(a[index] / 2)
        a[index] = v
        m -= 1
    """
    # 9 3 = 2*2*2+1 2+1
    # 10 2
    # 100 4
    # 1000 8
    # 10000 16

    # 3 3 1
    # total=7
    # cou=3
    #
    ab = [0] * n
    for i in range(n):
        ab[i] = len(bin(a[i])[2:]) - 1

    for i in range(m):
        for j in range(n):
            if (ab[j] > 0) and (((j < n - 1) and (ab[j] >= ab[j + 1])) or (ab[j] > 0)):
                ab[j] -= 1
                break


    return str(sum(ab))



if __name__ == "__main__":
    input_list = []
    while True:
        try:
            input1 = input()
            if not input1:
                break
            if len(input1) == 0:
                break
            input_list.append(input1)
        except EOFError:
            break
    print(get_answer(input_list))

Submission status: Wrong Answer

Solution code:
def get_answer(input_list):
    c_list = [int(v) for v in input_list[0].split(" ")]
    a = [int(v) for v in input_list[1].split(" ")]
    a = sorted(a, reverse=True)
    n = c_list[0]
    m = c_list[1]

    """
    for i in range(m):
        index = a.index(max(a))
        v = int(a[index] / 2)
        a[index] = v
        m -= 1
    """
    # 9 3 = 2*2*2+1 2+1
    # 10 2
    # 100 4
    # 1000 8
    # 10000 16

    # 3 3 1
    # 2 1 0
    # 1 2 1
    ab = [0] * n
    for i in range(n):
        ab[i] = len(bin(a[i])[2:]) - 1

    for i in range(m):
        for j in range(n):
            if ab[j] <= 0:
                continue
            if j < n - 1:
                if ab[j] >= ab[j + 1]:
                    ab[j] -= 1
                    break
            else:
                if ab[j] > 0:
                    ab[j] -= 1
                    break


    return str(sum(ab))



if __name__ == "__main__":
    input_list = []
    while True:
        try:
            input1 = input()
            if not input1:
                break
            if len(input1) == 0:
                break
            input_list.append(input1)
        except EOFError:
            break
    print(get_answer(input_list))

Submission status: Wrong Answer

Solution code:
from heapq import*;_,a=open(0);a=sorted([-int(x)for x in a.split()]);exec('heappush(a,-~heappop(a)//2);'*len(a));print(-sum(a))

Submission status: Wrong Answer

Solution code:
def main():
  from heapq import heapify,heappush,heappop
  n,m,*a=[-int(i)for i in open(0).read().split()]
  heapify(a)
  for _ in range(m):heappush(a,0--heappop(a)//2)
  print(-sum(a))
main()

Submission status: Wrong Answer

Solution code:
import heapq

N,M=( int(x) for x in input().split())
A=[int(s)*-1 for s in input().split()]

heapq.heapify(A)

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

Submission status: Wrong Answer

Solution code:
import heapq
N,Y=map(int,input().split())
a=[float(x) for x in input().split()]

for b in range(Y):
  heapq.heapify(a)
  a[N-1]=float(a[N-1])/2
v=0
for c in range(N):
  v+=int(a[c])
print(v)

Submission status: Wrong Answer

Solution code:
from heapq import heappush, heappop
N,M = [int(i) for i in input().split(' ')]
itemList = [int(i) for i in input().split(' ')]
heap = []

for i in itemList:
    heappush(heap, -i)

for _ in range(M):
    heappush(heap, heappop(heap)//2)
    
print(-sum(heap))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from sys import stdin
import heapq

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

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

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

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import numpy as np
import sys, math, time, random

class Heapque():
    
    def __init__(self):
        pass
        
    def pop(self, que):
        val = que.pop(1)
        
        return(que, val)
            
    def sort(self, que, i):
        index = int(math.floor(i/2))
        
        if index == 0:
            return(que)
            
        parent = que[index]
        child = que[i]
        
        if parent < child:
            que[index] = child
            que[i] = parent
            
            que = self.sort(que, index)
        
        else:
            return(que)
    
    def add(self, que, val):
        #print("def add: que", que)
        que.append(val)
        que = self.sort(que, len(que)-1)
        
        return(que)
        
if __name__ == "__main__":
    #n, m = map(int, input().split())
    m = random.randint(1, 10**5)
    #A_list = list(map(int, input().split()))
    A_list = [random.randint(1, 10**9)]*(10**5)
    
    start_time = time.time()
    que = sorted(A_list, reverse=True)
    end_time = time.time()
    #print(end_time - start_time)
    
    hq = Heapque()
    que.insert(0, 0)
    #print("A_list", A_list, type(A_list))
    
    #print(que)
    
    for i in range(m):
        #print(i)
        que, val = hq.pop(que)
        val = math.floor(val/2)
        que = hq.add(que, val)
        
    print(sum(que))
    end_time = time.time()
    #print(end_time - start_time)

Submission status: Wrong Answer

Solution code:
def get_answer(input_list):
    c_list = [int(v) for v in input_list[0].split(" ")]
    a = [int(v) for v in input_list[1].split(" ")]
    a = sorted(a, reverse=True)
    n = c_list[0]
    m = c_list[1]

    """
    for i in range(m):
        index = a.index(max(a))
        v = int(a[index] / 2)
        a[index] = v
        m -= 1
    """
    # 9 3 = 2*2*2+1 2+1
    # 10 2
    # 100 4
    # 1000 8
    # 10000 16

    # 3 3 1
    # 2 1 0
    # 1 2 1
    ab = [0] * n
    for i in range(n):
        ab[i] = len(bin(a[i])[2:]) - 1

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


    return str(sum(ab))



if __name__ == "__main__":
    input_list = []
    while True:
        try:
            input1 = input()
            if not input1:
                break
            if len(input1) == 0:
                break
            input_list.append(input1)
        except EOFError:
            break
    print(get_answer(input_list))

Submission status: Wrong Answer

Solution code:
def get_answer(input_list):
    c_list = [int(v) for v in input_list[0].split(" ")]
    a = [int(v) for v in input_list[1].split(" ")]
    a = sorted(a, reverse=True)
    n = c_list[0]
    m = c_list[1]

    """
    for i in range(m):
        index = a.index(max(a))
        v = int(a[index] / 2)
        a[index] = v
        m -= 1
    """
    # 9 3 = 2*2*2+1 2+1
    # 10 2
    # 100 4
    # 1000 8
    # 10000 16
    
    # 3 3 1
    # 2 1 0
    # 1 2 1
    ab = [0] * n
    for i in range(n):
        ab[i] = len(bin(a[i])[2:]) - 1


    return str(sum(ab))



if __name__ == "__main__":
    input_list = []
    while True:
        try:
            input1 = input()
            if not input1:
                break
            if len(input1) == 0:
                break
            input_list.append(input1)
        except EOFError:
            break
    print(get_answer(input_list))

Submission status: Wrong Answer

Solution code:
def get_answer(input_list):
    c_list = [int(v) for v in input_list[0].split(" ")]
    a = [int(v) for v in input_list[1].split(" ")]
    n = c_list[0]
    m = c_list[1]

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

    return str(sum(a))



if __name__ == "__main__":
    input_list = []
    while True:
        try:
            input1 = input()
            if not input1:
                break
            if len(input1) == 0:
                break
            input_list.append(input1)
        except EOFError:
            break
    print(get_answer(input_list))

Submission status: Wrong Answer

Solution code:
import heapq

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

heapq.heapify(price)
for i in range(m):
    a = heapq.heappop(price)//2
    heapq.heappush(price,a)
print(-sum(price))

Submission status: Wrong Answer

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

price.sort(reverse=True)
for i in range(n):
    # print(i+1)
    price[0] //= 2
    price.sort(reverse=True)
    # print(price)
print(sum(price))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np
def input():
    return sys.stdin.readline()[:-1]

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

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

for _ in range(M):
    max_index = np.argmax(A)
    print(max_index)
    A[max_index] = int(A[max_index] / 2)

print(sum(A))

Submission status: Wrong Answer

Solution code:
N, M=map(int, input().split())
A=list(map(int, input().split()))
A.sort()
B=[]
if N>M:
  A, B=A[N-M:], A[:N-M]
while M>0 and A:
  A[-1]=A[-1]//2
  A.sort()
  B.append(A.pop(0))
  M-=1
print(sum(B))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
# https://atcoder.jp/contests/abc141/tasks/abc141_d
import math
# 整数の入力
N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse=True)
if N > 1:
    while M > 0:
        for i in range(N-1):
            if A[i] >= A[N-1]:
                c = 1
                for j in range(1, M + 1):
                    if (A[i] * (1 / pow(2, j))) > A[i+1]:
                        c = j
                        continue
                    else:
                        break
                A[i] = math.floor(A[i] * (1 / pow(2, c)))
                M -= c
            else:
                A[N-1] = math.floor(A[N-1] * (1 / pow(2, 1)))
                M -= 1
            if M <= 0:
                break
else:
    A[0] = math.floor(A[0] * (1 / pow(2, M)))
print(sum(A))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
# https://atcoder.jp/contests/abc141/tasks/abc141_d
import math
# 整数の入力
N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse=True)
if N > 1:
    while M > 0:
        for i in range(N-1):
            if A[i] >= A[N-1]:
                c = 1
                for j in range(1, M):
                    if (A[i] * (1 / pow(2, j))) > A[i+1]:
                        c = j
                        continue
                    else:
                        break
                A[i] = math.floor(A[i] * (1 / pow(2, c)))
                M -= c
            else:
                A[N-1] = math.floor(A[N-1] * (1 / pow(2, 1)))
                M -= 1
            if M <= 0:
                break
else:
    A[0] = math.floor(A[0] * (1 / pow(2, M)))
print(sum(A))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
# https://atcoder.jp/contests/abc141/tasks/abc141_d
import math
# 整数の入力
N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse=True)
if N > 1:
    while M > 0:
        for i in range(N-1):
            if A[i] >= A[N-1]:
                c = 1
                for j in range(1, M):
                    c = j
                    if (A[i] * (1 / pow(2, j))) > A[i+1]:
                        continue
                    else:
                        break
                A[i] = math.floor(A[i] * (1 / pow(2, c)))
                M -= c
            else:
                A[N-1] = math.floor(A[N-1] * (1 / pow(2, 1)))
                M -= 1
            if M <= 0:
                break
else:
    A[0] = math.floor(A[0] * (1 / pow(2, M)))
print(sum(A))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
# https://atcoder.jp/contests/abc141/tasks/abc141_d
import math
# 整数の入力
N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse=True)
if N > 1:
    while M > 0:
        for i in range(N-1):
            if A[i] >= A[N-1]:
                if (A[i] * 0.5) > A[i+1]:
                    A[i] = math.floor(A[i] * (1 / pow(2, 1)))
                    M -= 1
                    if M <= 0:
                        break
                    else:
                        continue
                else:
                    A[i] = math.floor(A[i] * (1 / pow(2, 1)))
                    M -= 1
            else:
                A[N-1] = math.floor(A[N-1] * (1 / pow(2, 1)))
                M -= 1
            if M <= 0:
                break
else:
    A[0] = math.floor(A[0] * (1 / pow(2, M)))
print(sum(A))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
# https://atcoder.jp/contests/abc141/tasks/abc141_d
import math
# 整数の入力
N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse=True)
if N > 1:
    while M > 0:
        for i in range(N-1):
            if A[i] >= A[N-1]:
                A[i] = math.floor(A[i] * (1 / pow(2, 1)))
            else:
                A[N-1] = math.floor(A[N-1] * (1 / pow(2, 1)))
            M -= 1
            if M <= 0:
                break
else:
    A[0] = math.floor(A[0] * (1 / pow(2, M)))
print(sum(A))

Submission status: Wrong Answer

Solution code:
import heapq

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

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

print(-sum(A))

Submission status: Wrong Answer

Solution code:
import bisect

N, M = map(int, input().split())
prices = list(map(int, input().split()))
lb = 0
rb = 10**14
while lb <= rb:
  mid = (lb+rb)//2
  cnt = 0
  for price in prices:
    idx = 0
    while price > mid:
      price  = price//2
      idx += 1
    cnt += idx
  if cnt > M:
    lb = mid + 1
  else:
    rb = mid - 1
sum_p = 0
cnt = 0
for price in prices:
  while price > lb:
    price = price // 2
    cnt += 1
  sum_p += price
if cnt < M:
  sum_p -= lb*(M-cnt)//2
print(sum_p)

Submission status: Wrong Answer

Solution code:
import bisect

N, M = map(int, input().split())
prices = list(map(int, input().split()))
lb = 0
rb = 10**14
while lb <= rb:
  mid = (lb+rb)//2
  cnt = 0
  for price in prices:
    idx = 0
    while price > mid:
      price  = price//2
      idx += 1
    cnt += idx
  if cnt > M:
    lb = mid + 1
  else:
    rb = mid - 1
sum_p = 0
cnt = 0
for price in prices:
  while price >= lb and cnt < M:
    price = price // 2
    cnt += 1
  sum_p += price
print(sum_p)

Submission status: Wrong Answer

Solution code:
import bisect

N, M = map(int, input().split())
prices = list(map(int, input().split()))
lb = 0
rb = 10**14
while lb <= rb:
  mid = (lb+rb)//2
  cnt = 0
  for price in prices:
    idx = 0
    while price > mid:
      price  = price//2
      idx += 1
    cnt += idx
  if cnt > M:
    lb = mid + 1
  else:
    rb = mid - 1
sum_p = 0
cnt = 0
for price in prices:
  while price >= lb and cnt < M:
    price = price // 2
    cnt += 1
  sum_p += price
print(sum_p)

Submission status: Wrong Answer

Solution code:
import bisect

N, M = map(int, input().split())
prices = list(map(int, input().split()))
lb = 0
rb = 10**14
while lb <= rb:
  mid = (lb+rb)//2
  cnt = 0
  for price in prices:
    idx = 0
    while price > mid:
      price  = price//2
      idx += 1
    cnt += idx
  if cnt > M:
    lb = mid + 1
  else:
    rb = mid - 1
sum_p = 0
for price in prices:
  while price > lb:
    price = price // 2
  sum_p += price
print(sum_p)

Submission status: Wrong Answer

Solution code:
import heapq

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

def pop():
    return -heapq.heappop(a)

def push(x):
    return heapq.heappush(a, -x)

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

print(-sum(a))

Submission status: Wrong Answer

Solution code:
import math
import heapq

def heapsort(iterable):
    h = []
    for value in iterable:
        heapq.heappush(h, value)
    return [heapq.heappop(h) for i in range(len(h))]
  
n,m = map(int,input().split())
A = list(map(int,input().split()))
def calc(n):
  return math.floor(n)
  
for i in range(m):
  heapsort(A)
  A[0] /= 2 
A = map(calc,A)
print(sum(A))

Submission status: Wrong Answer

Solution code:
from heapq import heappushpop, heappush, heappop, heapify
N, M = map(int, input().split())
a = [-int(a) for a in input().split()]
heapify(a)
t = heappop(a) / 2
for _ in range(M):
  t = heappushpop(a, t) / 2
heappush(a, t)
print(sum(int(-x) for x in a))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import heapq

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

for i in range(N):
    heapq.heappush(hq, A[i]*(-1))

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

Submission status: Wrong Answer

Solution code:
import math
 
s=list(map(int,input().split()))
t=list(map(int,input().split()))
a=0
b=0
c=0
d=s[1]
t.sort(reverse=True)
if s[0]==1:
  for i in range(s[1]):
    t[0]=math.floor(t[0]/2)
else:
  c=t[0]/2
  for j in range(s[1]):
    for l in range(s[0]):
      if d>0:
        if c<=t[l]:
          t[l]=math.floor(t[l]/2)
          d=d-1
        else:
            t.sort(reverse=True)
            c=t[0]/2
            continue
      else:
        break
print(sum(t))

Submission status: Wrong Answer

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

A_sub = input().split(" ")
A = [int(n0) for n0 in A_sub]

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

if N >1:
    for xi in range(M):
        for yi in range(N-1):
            if A[yi]>A[yi+1]:
                A[yi]= A[yi]//2
                break

    sum = 0
    for yi in range(N):
        sum = sum + A[yi]
    print(sum)
else:
    for yi in range(M):
        A[0]= A[0]//2
    print(A[0])

Submission status: Wrong Answer

Solution code:
import math
 
s=list(map(int,input().split()))
t=list(map(int,input().split()))
a=0
b=0
c=0
t.sort(reverse=True)
if s[0]==1:
  for i in range(s[1]):
    t[0]=math.floor(t[0]/2)
else:
  c=math.floor(t[0]/2)
  for j in range(s[1]):
    for l in range(s[0]):
      if s[1]>0:
        if c<=t[l]:
          t[l]=math.floor(t[l]/2)
          s[1]=s[1]-1
        else:
            t.sort(reverse=True)
            c=math.floor(t[0]/2)
            continue
      else:
        break
print(sum(t))

Submission status: Wrong Answer

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

A_sub = input().split(" ")
A = [int(n0) for n0 in A_sub]

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

if N >1:
    for xi in range(M):
        for yi in range(N-1):
            if A[yi]>A[yi+1]:
                A[yi]= A[yi]//2
                break

    sum = 0
    for yi in range(N):
        sum = sum + A[yi]
    print(sum)
else:
    print(A[0]//2**M)

Submission status: Wrong Answer

Solution code:
import os
import heapq
import math

N, M = (int(x) for x in input().split())
cost = [-a for a in map(int, input().split())]
heapq.heapify(cost)

for _ in range(0,M):
    x = heapq.heappop(cost)
    heapq.heappush(cost, math.floor(x/2))

res = 0
for i in range(0, N):
    res += (cost[i]*-1)

print(res)

Submission status: Wrong Answer

Solution code:
import heapq

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

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

print(sum(list(map(lambda x: x*(-1), value))))

Submission status: Wrong Answer

Solution code:
import sys
N, M = map(int,input().split())
A = list(map(int,input().split()))
if N == 1:
    while A[0] > 0:
        A[0] = A[0]//2
    print(0)
    sys.exit()

list.sort(A,reverse = True)
a = A[0]
b = A[1]
for _ in range(M):
    a = A[0]
    b = A[1]
    while a >= b:
        a = a//2
    A[0] = a
    for i in range(0,N-1):
        if A[i] < A[i+1]:
            A[i] , A[i+1] = A[i+1] , A[i]

print(sum(A))

Submission status: Wrong Answer

Solution code:
import sys
N, M = map(int,input().split())
A = list(map(int,input().split()))
if N == 1:
    while A[0] > 0:
        A[0] = A[0]//2
    print(0)
    sys.exit()

list.sort(A,reverse = True)
for _ in range(M):
    while A[0] >= A[1]:
        A[0] = A[0]//2
    for i in range(0,N-1):
        if A[i] < A[i+1]:
            A[i] , A[i+1] = A[i+1] , A[i]

print(sum(A))

Submission status: Wrong Answer

Solution code:
x, y = map(int,input().split())

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

lis.sort(reverse = True)
i = 0
while y>0:
  if lis[i%x]>2:
    lis[i%x] = lis[i%x]//2
    y-=1
  i+=1


print(sum(lis))

Submission status: Wrong Answer

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

def sorte(x):
  tmp = x[0] // 2
  j=0
  del x[0]
  if n != 1:
    while tmp<x[j] and j<n-2:
      j += 1
  x.insert(j,tmp)
  
 
a.sort(reverse = True)

while k > 0:
  sorte(a)
  k -= 1

sum=0
for i in range(n):
  sum += a[i]

print(sum)

Submission status: Wrong Answer

Solution code:
import sys
import math
import numpy as np
from heapq import heappush, heappop
pos=input()
pos=pos.split()
N=int(pos[0])
M=int(pos[1])
sum=0

item=input()
item=item.split()
item=list(map(float,item))

hq=[]
for i in item:
  heappush(hq,-i)
  
for i in range(1,M+1):
  temp=heappop(hq)
  heappush(hq,temp/2)
  
for j in range(0,len(item)):
  sum+=-1.0*heappop(hq)
  
print(math.floor(sum))

Submission status: Wrong Answer

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

def pop_heap(list):
		list[0] = list[len(list)-1]
		list.pop(len(list)-1)
		
		i = 0
		while 2*i + 1 < len(list) - 1:
				j = 2*i + 1
				if (j != n-1) and (list[j+1] > list[j]):
						j += 1
				
				if list[j] > list[i]:
						tmp = list[j]
						list[j] = list[i]
						list[i] = tmp
				i = j


def push_heap(list, ele):
		list.append(ele)

		n = len(list) - 1
		while n != 0:
				p = int(n/2)
				if list[n] > list[p]:
						tmp = list[n]
						list[n] = list[p]
						list[p] = tmp
				n = p

A = sorted(A, reverse=True)
for i in range(m):
		mx = A[0]
		pop_heap(A)
		push_heap(A, int(mx/2))

print(sum(A))

Submission status: Wrong Answer

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

def pop_heap(list):
		list[0] = list[len(list)-1]
		list.pop(len(list)-1)
		
		i = 0
		while 2*i + 1 < len(list) - 1:
				j = 2*i + 1
				if (j != n-1) and (list[j+1] > list[j]):
						j += 1
				
				if list[j] > list[i]:
						tmp = list[j]
						list[j] = list[i]
						list[i] = tmp
				i = j


def push_heap(list, ele):
		list.append(ele)

		n = len(list) - 1
		while n != 0:
				p = int(n/2)
				if list[n] > list[p]:
						tmp = list[n]
						list[n] = list[p]
						list[p] = tmp
				n = p

A = sorted(A, reverse=True)
for i in range(m):
		mx = A[0]
		pop_heap(A)

		push_heap(A, int(mx/2))

print(sum(A))

Submission status: Wrong Answer

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


def counthappy(s):
    happy = 0
    for i in range(0, len(s)):
        if i != 0 and s[i] == 'L':
            if s[i - 1] == 'L':
                happy += 1
        elif i != len(s) - 1 and s[i] == 'R':
            if s[i + 1] == 'R':
                happy += 1
    return happy


flag = 0
s_ = []
for i in range(0, N - 1):
    if S[i] != S[i + 1]:
        s_.append(S[flag:i + 1])
        flag = i + 1
        if flag == N - 1:
            s_.append(S[flag:N])

count = 0
for i in range(1, len(s_), 2):
    count += 1
    if s_[i][0] == 'L':
        s_[i] = s_[i].replace('L', 'R')
    elif s_[i][0] == 'R':
        s_[i] = s_[i].replace('R', 'L')

    if count == K:
        break

s_join = ''.join(s_)

happy = counthappy(s_join)
print(happy)

Submission status: Wrong Answer

Solution code:
inpl = lambda: list(map(int,input().split()))
N, M = inpl()
A = inpl()
A.sort(reverse=True)
L = list(map(lambda a: len(bin(a))-2,A))
L.append(0)
l = L[0]
P = []
D = []
for i in range(N+1):
    if L[i] == l:
        continue
    elif i > M:
        break
    else:
        d = l - L[i]
        r = M // i
        if d < r:
            P.append(i)
            D.append(d)
            M -= d*i
        else:
            P.append(i)
            D.append(r)
            M -= r*i
            break
E = [0]
for dd in D[::-1]:
    E.append(E[-1]+dd)
i = 0
for n in range(len(P)):
    while i < P[n]:
        A[i] >>= E[-n-1]
        i += 1
A.sort(reverse=True)
for m in range(min(M,N)):
    A[m] >>= 1

print(sum(A))

Submission status: Wrong Answer

Solution code:
import heapq
N,M=[int(thing) for thing in input().split(" ")]
A_list=[int(thing)*(-1) for thing in input().split(" ")]
heapq.heapify(A_list)
for aaaaa in range(M):
    thing =heapq.heappop(A_list)/2
    heapq.heappush(A_list,thing)
print(sum([thing*-1//1 for thing in A_list]))

Submission status: Wrong Answer

Solution code:
import numpy as np
import random

n,m = [int(s) for s in input().split()]
price = np.array([float(s) + (random.random() * 0.001) for s in input().split()])

for i in range(m):
  price = np.where(price == np.max(price),price/2,price)
  

answer = 0
for i in price.tolist():
  answer += int(i)
print(answer)

Submission status: Wrong Answer

Solution code:
inpl = lambda: list(map(int,input().split()))
N, M = inpl()
A = inpl()
A.sort(reverse=True)
L = list(map(lambda a: len(bin(a))-2,A))
L.append(0)
l = L[0]
P = []
D = []
for i in range(N+1):
    if L[i] == l:
        continue
    elif i > M:
        break
    else:
        d = l - L[i]
        r = M // i
        if d < r:
            P.append(i)
            D.append(d)
            M -= d*i
        else:
            P.append(i)
            D.append(r)
            M -= r*i
            break
c = 0
E = [0]
for dd in D:
    E.append(E[-1]+dd)
i = 0
for n in range(len(P)):
    while i < P[n]:
        A[i] >>= E[-n-1]
        i += 1
A.sort(reverse=True)
for m in range(min(M,N)):
    A[m] >>= 1

print(sum(A))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math

n, m = input().split()
n, m = [int(n), int(m)]
prices = list(map(int, input().split()))
prices.sort(reverse=True)
total = 0
for x in prices:
    y = math.floor(math.log(x))
    if m>0:
      if(y<=m):
        m -= y
        total += math.floor(x/math.pow(2,y))
        #print(m, total, x, y)
      else:
        total += math.floor(x/math.pow(2,m))
        #print(m, total, x, m)
        m = 0
    else:
      total += x
print(total)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
inl = list(map(int, input().split()))
for i in range(m):
  mx = 0
  th = 0
  for j in range(n):
    if inl[j] > mx:
      mx = inl[j]
      th = j
  inl[j] = int(inl[j]/2)
sum = 0
for k in range(n):
  sum += inl[k]
print(sum)

Submission status: Wrong Answer

Solution code:

import math
import numpy as np
pos=input()
pos=pos.split()
N=int(pos[0])
M=int(pos[1])

item=input()
item=item.split()
item=[float(d) for d in item]
npitem=np.array(item)
for i in np.arange(1,M+1):
  npitem[np.argmax(npitem)]=np.max(npitem)/2.0
    
print(int(np.floor(np.sum(npitem))))

Submission status: Wrong Answer

Solution code:

import math
import numpy as np
pos=input()
pos=pos.split()
N=int(pos[0])
M=int(pos[1])

item=input()
item=item.split()
item=[float(d) for d in item]
npitem=np.array(item)
for i in np.arange(1,M+1):
  print(np.max(npitem))
  npitem[np.argmax(npitem)]=np.max(npitem)/2.0
    
print(int(np.floor(np.sum(npitem))))

Submission status: Wrong Answer

Solution code:
import sys
import math
pos=input()
pos=pos.split()
N=int(pos[0])
M=int(pos[1])

item=input()
item=item.split()
item=[float(d) for d in item]
for i in range(1,M+1):
    print(max(item))
    item[item.index(max(item))]=math.floor(max(item)/(2.0))
    
print(int(sum(item)))

Submission status: Wrong Answer

Solution code:
import heapq

mnum, gnum = map(int, input().split())
array = list(map(lambda a: -int(a), input().split()))

array.sort()
heapq.heapify(array)

for i in range(gnum):
	temp = heapq.heappop(array)
	temp = temp/2
	heapq.heappush(array, temp)
    
print(sum(array)*-1)

Submission status: Wrong Answer

Solution code:
import heapq

mnum, gnum = map(int, input().split())
array = list(map(int, input().split()))

array.sort()
heapq.heapify(array)

for i in range(gnum):
	temp = heapq.heappop(array)
	temp = temp/2
	heapq.heappush(array, temp)
    
print(sum(array))

Submission status: Wrong Answer

Solution code:
import numpy as np
n,m = map(int,input().split())
l = np.array(list(map(int,input().split())))
while m >= 0:
  l[np.argmax(l)] = int(l[np.argmax(l)]//2)
  m -= 1

print(np.sum(l))

Submission status: Wrong Answer

Solution code:
while True:
	try:
		N, M = map(int, input().split())
		A = list(map(int, input().split()))
		if (N == 1):
			for i in range(M):
				A[0] //= 2
			print(A[0])
			continue
			
		while (M > 0):
			A.sort()
			n = A.pop()
			while (M > 0 and n >= A[-1]):
				n //= 2
				M -= 1
			A.append(n)
			print(A)
		print(sum(A))
	except:
		break