Buggy python submission (verdict: Time Limit Exceeded):
def main():
    
    n,m = map(int,input().split())
    l = list(input())
    l = l[::-1]
    count = [-1]*(n+1)
    count[0] = 0
    check = 1
    i = 0

    while i < n+1:
        if count[i] != -1:
            a = -1
            for j in range(1,m+1):
                if i+j < n+1 and l[i+j] != "1":
                    count[i+j] = check
                    a = i+j
            
            check += 1
            if a == -1:
                print(-1)
                exit()
            else:
                i = a
            
            if count[-1] != -1:
                break
    count = count[::-1]

    ans = []
    a = 0
    for i in range(check-2,-1,-1):
        b = count.index(i)
        ans.append(b-a)
        a = b
    print(*ans)

if __name__ == "__main__":
    main()


Fixed submission:
def main():
    
    n,m = map(int,input().split())
    l = list(input())[::-1]
    ans = []
    i = 0
    l[0] = 0

    while i < n+1:
        if l[i] == 0:
            a = -1
            for j in range(m,0,-1):
                if i+j < n+1 and l[i+j] != "1":
                    a = i+j
                    ans.append(j)
                    l[a] = 0
                    break
            if a == -1:
                print(-1)
                exit()
            else:
                i = a
            
            if l[-1] == 0:
                break
    
    print(*ans[::-1])

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    
    n,m = map(int,input().split())
    l = list(input())
    l = l[::-1]
    count = [-1]*(n+1)
    count[0] = 0
    check = 1
    i = 0

    while i < n+1:
        if count[i] != -1:
            a = -1
            for j in range(1,m+1):
                if i+j < n+1 and l[i+j] != "1":
                    count[i+j] = check
                    a = i+j
            
            check += 1
            if a == -1:
                print(-1)
                exit()
            else:
                i = a
            
            if count[-1] != -1:
                break
    count = count[::-1]

    ans = []
    a = 0
    for i in range(check-2,-1,-1):
        b = count.index(i)
        ans.append(b-a)
        a = b
    print(*ans)

if __name__ == "__main__":
    main()


Fixed submission:
def main():
    
    n,m = map(int,input().split())
    l = list(input())[::-1]
    ans = []
    i = 0
    l[0] = 0

    while i < n+1:
        if l[i] == 0:
            a = -1
            for j in range(m,0,-1):
                if i+j < n+1 and l[i+j] != "1":
                    a = i+j
                    ans.append(j)
                    l[a] = 0
                    break
            if a == -1:
                print(-1)
                exit()
            else:
                i = a
            
            if l[-1] == 0:
                break
    
    print(*ans[::-1])

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
l = list(input())
l = l[::-1]
count = [-1]*(n+1)
count[0] = 0
check = 1
i = 0

while i < n+1:
    if count[i] != -1:
        a = -1
        for j in range(1,m+1):
            if i+j < n+1 and l[i+j] != "1":
                count[i+j] = check
                a = i+j
        
        check += 1
        if a == -1:
            print(-1)
            exit()
        else:
            i = a
        
        if count[-1] != -1:
            break
count = count[::-1]

ans = []
a = 0
for i in range(check-2,-1,-1):
    b = count.index(i)
    ans.append(b-a)
    a = b
print(*ans)




Fixed submission:
def main():
    
    n,m = map(int,input().split())
    l = list(input())[::-1]
    ans = []
    i = 0
    l[0] = 0

    while i < n+1:
        if l[i] == 0:
            a = -1
            for j in range(m,0,-1):
                if i+j < n+1 and l[i+j] != "1":
                    a = i+j
                    ans.append(j)
                    l[a] = 0
                    break
            if a == -1:
                print(-1)
                exit()
            else:
                i = a
            
            if l[-1] == 0:
                break
    
    print(*ans[::-1])

if __name__ == "__main__":
    main()