Problem p02683 (python)

Fixed submission:
import itertools
n, m, x = map(int, input().split())
T = [list(map(int, input().split())) for _ in range(n)]

flag1 = True
ans = -1

for i in range(1, n + 1):
    if i == 1:
        for j in range(n):
            flag = True
            for k in range(m):
                if T[j][k + 1] < x:
                    flag = False
                    break

            if flag == True and flag1 == True:
                ans = T[j][0]
                flag1 = False
            elif flag == True:
                ans = min(ans, T[j][0])

    else:
        tmp = list(itertools.combinations(range(1, n + 1), i))
        for j in range(len(tmp)):
            flag = True
            M = [0] * m
            tmp1 = 0
            for k in range(len(tmp[j])):
                for l in range(m):
                    M[l] = M[l] + T[tmp[j][k] - 1][l + 1]
                tmp1 = tmp1 + T[tmp[j][k] - 1][0]

            for k in range(m):
                if M[k] < x:
                    flag = False
                    break

            if flag == True and flag1 == True:
                ans = tmp1
                flag1 = False
            elif flag == True:
                ans = min(ans, tmp1)

print(ans)

Buggy submission (verdict: Runtime Error):
import itertools
n, m, x = map(int, input().split())
T = [list(map(int, input().split())) for _ in range(n)]

flag1 = True
ans = -1

for i in range(1, n + 1):
    if i == 1:
        for j in range(n):
            flag = True
            for k in range(m):
                if T[j][k + 1] < x:
                    flag = False
                    break

            if flag == True and flag1 == True:
                ans = T[j][0]
                flag1 = False
            elif flag == True:
                ans = min(ans, T[j])

    else:
        tmp = list(itertools.combinations(range(1, n + 1), i))
        for j in range(len(tmp)):
            flag = True
            M = [0] * m
            tmp1 = 0
            for k in range(len(tmp[j])):
                for l in range(m):
                    M[l] = M[l] + T[tmp[j][k] - 1][l + 1]
                tmp1 = tmp1 + T[tmp[j][k] - 1][0]

            for k in range(m):
                if M[k] < x:
                    flag = False
                    break

            if flag == True and flag1 == True:
                ans = tmp1
                flag1 = False
            elif flag == True:
                ans = min(ans, tmp1)

print(ans)

Buggy submission (verdict: Runtime Error):
import itertools
n, m, x = map(int, input().split())
T = [list(map(int, input().split())) for _ in range(n)]

A = list(range(1, n + 1))
flag1 = True
ans = -1

for i in range(1, n + 1):
    if i == 1:
        for j in range(n):
            flag = True
            for k in range(m):
                if T[j][k] < x:
                    flag = False
                    break

            if flag == True and flag1 == True:
                ans = T[j]
                flag1 = False
            elif flag == True:
                ans = min(ans, T[j])

    else:
        tmp = list(itertools.combinations(range(1, n + 1), i))
        for j in range(len(tmp)):
            flag = True
            M = [0] * m
            tmp1 = 0
            for k in range(len(tmp[j])):
                for l in range(m):
                    M[l] = M[l] + T[tmp[j][k] - 1][l + 1]
                tmp1 = tmp1 + T[tmp[j][k] - 1][0]

            for k in range(m):
                if M[k] < x:
                    flag = False
                    break

            if flag == True and flag1 == True:
                ans = tmp1
                flag1 = False
            elif flag == True:
                ans = min(ans, tmp1)


print(ans)