Problem p02912 (python)

Fixed submission:
import sys
n,m = map(int,input().split())
lst_a = list(map(int,input().split()))
temp = 0
cnt = 0
fin = 0
loop = 0
debug = 0
temp2 = 0
if n == 1:
    for i in range(m):
        lst_a[0] //= 2
    print(lst_a[0])
    sys.exit()
while debug < 10:
    loop = 0
    #temp2 = temp
    temp = 0
    lst_a.sort(reverse=True)
    while loop < n-1:
        lst_a[loop] //= 2
        cnt += 1
        temp = max(temp,lst_a[loop])
        if cnt == m:
            #print(lst_a)
            print(sum(lst_a))
            sys.exit()
        if temp > max(lst_a[loop],lst_a[loop + 1]):
            break
        if lst_a[loop + 1] > lst_a[loop]:
            loop += 1
        
        
        
"""        if lst_a[loop] >= max(lst_a[loop + 1],temp):
            lst_a[loop] //= 2
            temp = max(lst_a[loop],lst_a[loop+1])
            cnt += 1
            if cnt == m:
                print(sum(lst_a))
                sys.exit()
            if temp > lst_a[loop + 1]:
                break
            
            
        loop += 1
    
    #debug += 1
print(lst_a[99999])
# print(temp)
# print(cnt)
# print(lst_a)
# print(sum(lst_a))
"""

Buggy submission (verdict: Runtime Error):
import numpy as np
import sys
n,m = map(int,input().split())
list_a = list(map(int,input().split()))
#b_list = list(map(int,input().split()))
#print(" ".join(map(str,c_list)))
list_a.sort(reverse = True)
a_max = list_a[0] // 2
list_a[0] = a_max
count = 1
if m == 1:
    print(sum(list_a))
    sys.exit()
for i in range(m-1):
    if list_a[np.argmax(list_a[0:count])] < list_a[count]:
        #print(list_a[np.argmax(list_a[0:count])],list_a[count])
        list_a[count] = list_a[count] // 2 
        count += 1
    else:
        list_a[np.argmax(list_a[0:count])] = list_a[np.argmax(list_a[0:count])] // 2
        #print(list_a[np.argmax(list_a[0:count])])
print(sum(list_a))
"""
for i in range(m):
    count = 0
    while count == 0:

        for j in range(n):
            
            if list_a[j] > a_max:
                list_a[j] = list_a[j]//2
                a_max = a_max//2
                count = 1 
                print("c=1")
                print(a_max)
                print(list_a)
                break
        if count == 0:
            a_max -= 1
            print("c=0")
    
print(list_a)
"""

Buggy submission (verdict: Runtime Error):
import numpy as np

n,m = map(int,input().split())
list_a = list(map(int,input().split()))
#b_list = list(map(int,input().split()))
#print(" ".join(map(str,c_list)))
list_a.sort(reverse = True)
a_max = list_a[0] // 2
list_a[0] = a_max
count = 2
for i in range(m-1):
    if list_a[np.argmax(list_a[0:count])] < list_a[count]:
        #print(list_a[np.argmax(list_a[0:count])],list_a[count])
        list_a[count] = list_a[count] // 2 
        count += 1
    else:
        list_a[np.argmax(list_a[0:count])] = list_a[np.argmax(list_a[0:count])] // 2
        #print(list_a[np.argmax(list_a[0:count])])
    
print(sum(list_a))
"""
for i in range(m):
    count = 0
    while count == 0:

        for j in range(n):
            
            if list_a[j] > a_max:
                list_a[j] = list_a[j]//2
                a_max = a_max//2
                count = 1 
                print("c=1")
                print(a_max)
                print(list_a)
                break
        if count == 0:
            a_max -= 1
            print("c=0")
    
print(list_a)
"""