Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

N, Y = map(int, input().split())
result_10000, result_5000, result_1000 = -1, -1, -1
found = False

# 効率を考えて、1万円札 → 5000円札 → 1000円札の順で求める
# 1万円札の数をY//10000から一つずつ減らして調べていく
for num_10000 in reversed(range(0, Y//10000 + 1)):
    y_10000 = Y - 10000 * num_10000
    n_10000 = N - num_10000
    if y_10000 == 0 and n_10000 == 0:
        result_10000, result_5000, result_1000 = num_10000, 0, 0
        found = True
        break
    else:
        for num_5000 in reversed(range(0, y_10000//5000 + 1)):
            y_5000 = y_10000 - 5000 * num_5000
            n_5000 = n_10000 - num_5000
            if y_5000 == 0 and n_5000 == 0 and num_10000 + num_5000 == N:
                result_10000, result_5000, result_1000 = num_10000, num_5000, 0
                found = True
                break
            else:
                # for num_1000 in reversed(range(0, y_5000//1000 + 1)):
                #     y_1000 = y_5000 - 1000 * num_1000
                #     n_1000 = n_5000 - num_1000
                #     if y_1000 == 0 and n_1000 == 0 and num_10000 + num_5000 + num_1000 == N:
                #         result_10000, result_5000, result_1000 = num_10000, num_5000, num_1000
                #         found = True
                #         break
                num_1000 = y_5000 // 1000
                y_1000 = y_5000 - 1000 * num_1000
                n_1000 = n_5000 - num_1000
                if y_1000 == 0 and n_1000 == 0 and num_10000 + num_5000 + num_1000 == N:
                    result_10000, result_5000, result_1000 = num_10000, num_5000, num_1000
                    found = True
                    break
            if found:
                break
    if found:
        break
    
print(result_10000, result_5000, result_1000)



Fixed submission:
# -*- coding: utf-8 -*-

N, Y = map(int, input().split())
result_10000, result_5000, result_1000 = -1, -1, -1
found = False

# 効率を考えて、1万円札 → 5000円札 → 1000円札の順で求める
# 1万円札の数をY//10000から一つずつ減らして調べていく
for num_10000 in reversed(range(0, Y//10000 + 1)):
    y_10000 = Y - 10000 * num_10000
    n_10000 = N - num_10000
    if y_10000 == 0 and n_10000 == 0:
        result_10000, result_5000, result_1000 = num_10000, 0, 0
        found = True
        break
    else:
        for num_5000 in reversed(range(0, y_10000//5000 + 1)):
            y_5000 = y_10000 - 5000 * num_5000
            n_5000 = n_10000 - num_5000
            if y_5000 < 0 or n_5000 < 0:
                break
            if y_5000 == 0 and n_5000 == 0 and num_10000 + num_5000 == N:
                result_10000, result_5000, result_1000 = num_10000, num_5000, 0
                found = True
                break
            else:
                # 10000円札と5000円札の枚数が決まれば必然的に1000円札の枚数は決まる
                num_1000 = y_5000 // 1000
                y_1000 = y_5000 - 1000 * num_1000
                n_1000 = n_5000 - num_1000
                if y_1000 == 0 and n_1000 == 0 and num_10000 + num_5000 + num_1000 == N:
                    result_10000, result_5000, result_1000 = num_10000, num_5000, num_1000
                    found = True
                    break
            if found:
                break
        if found:
            break
    
print(result_10000, result_5000, result_1000)

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

N, Y = map(int, input().split())
result_10000, result_5000, result_1000 = -1, -1, -1
found = False

# 効率を考えて、1万円札 → 5000円札 → 1000円札の順で求める
# 1万円札の数をY//10000から一つずつ減らして調べていく
for num_10000 in reversed(range(0, Y//10000 + 1)):
    y_10000 = Y - 10000 * num_10000
    n_10000 = N - num_10000
    if y_10000 == 0 and n_10000 == 0:
        result_10000, result_5000, result_1000 = num_10000, 0, 0
        found = True
        break
    else:
        for num_5000 in reversed(range(0, y_10000//5000 + 1)):
            y_5000 = y_10000 - 5000 * num_5000
            n_5000 = n_10000 - num_5000
            if y_5000 == 0 and n_5000 == 0 and num_10000 + num_5000 == N:
                result_10000, result_5000, result_1000 = num_10000, num_5000, 0
                found = True
                break
            else:
                for num_1000 in reversed(range(0, y_5000//1000 + 1)):
                    y_1000 = y_5000 - 1000 * num_1000
                    n_1000 = n_5000 - num_1000
                    if y_1000 == 0 and n_1000 == 0 and num_10000 + num_5000 + num_1000 == N:
                        result_10000, result_5000, result_1000 = num_10000, num_5000, num_1000
                        found = True
                        break
            if found:
                break
    if found:
        break
    
print(result_10000, result_5000, result_1000)



Fixed submission:
# -*- coding: utf-8 -*-

N, Y = map(int, input().split())
result_10000, result_5000, result_1000 = -1, -1, -1
found = False

# 効率を考えて、1万円札 → 5000円札 → 1000円札の順で求める
# 1万円札の数をY//10000から一つずつ減らして調べていく
for num_10000 in reversed(range(0, Y//10000 + 1)):
    y_10000 = Y - 10000 * num_10000
    n_10000 = N - num_10000
    if y_10000 == 0 and n_10000 == 0:
        result_10000, result_5000, result_1000 = num_10000, 0, 0
        found = True
        break
    else:
        for num_5000 in reversed(range(0, y_10000//5000 + 1)):
            y_5000 = y_10000 - 5000 * num_5000
            n_5000 = n_10000 - num_5000
            if y_5000 < 0 or n_5000 < 0:
                break
            if y_5000 == 0 and n_5000 == 0 and num_10000 + num_5000 == N:
                result_10000, result_5000, result_1000 = num_10000, num_5000, 0
                found = True
                break
            else:
                # 10000円札と5000円札の枚数が決まれば必然的に1000円札の枚数は決まる
                num_1000 = y_5000 // 1000
                y_1000 = y_5000 - 1000 * num_1000
                n_1000 = n_5000 - num_1000
                if y_1000 == 0 and n_1000 == 0 and num_10000 + num_5000 + num_1000 == N:
                    result_10000, result_5000, result_1000 = num_10000, num_5000, num_1000
                    found = True
                    break
            if found:
                break
        if found:
            break
    
print(result_10000, result_5000, result_1000)