Problem p03326 (python)

Fixed submission:
# from itertools import product

INF = 10**18

N, M = map(int, input().split())
XYZ = [list(map(int, input().split())) for _ in range(N)]

# i番目までのケーキの内、j個食べた時のpointの最大値
# (ただしpointの計算時には、8通りのmaskを乗算する)

def mul_mask(l, mask):
    p = []
    for i, m in enumerate(l):
        p.append(m*mask[i])
        # print(p)
    return p
    # return [a*b for a, b in zip(l, mask)]

dp_std = [[-INF for _ in range(M+1)] for _ in range(N+1)]
for i in range(N+1):
    dp_std[i][0] = 0
# print(dp_std)

max_p = -INF
# masks = product([-1, 1], repeat=3)
masks = []
for i in [1, -1]:
    for j in [1, -1]:
        for k in [1, -1]:
            masks.append([i, j, k])
# print(masks)
for mask in masks:
    dp = dp_std[:]
    for i in range(1, N+1):
        score = sum(mul_mask(XYZ[i-1], mask))
        for j in range(1, M+1):
            # print(i, j, XYZ[i-1], mask)
            dp[i][j] = max(
                dp[i-1][j],
                dp[i-1][j-1] + score
            )
            # for dp_i in dp:
            #     print(dp_i)
    p = dp[N][M]
    max_p = max(max_p, p)
    # print(p)

print(max_p)

Buggy submission (verdict: Runtime Error):
# from itertools import product

INF = 10**18

N, M = map(int, input().split())
XYZ = [list(map(int, input().split())) for _ in range(N)]

# i番目までのケーキの内、j個食べた時のpointの最大値
# (ただしpointの計算時には、8通りのmaskを乗算する)

def mul_mask(l, mask):
    p = []
    for i, m in enumerate(l):
        p.append(m*mask[i])
        # print(p)
    return p
    # return [a*b for a, b in zip(l, mask)]

dp_std = [[-INF for _ in range(M+1)] for _ in range(N+1)]
for i in range(N+1):
    dp_std[i][0] = 0
# print(dp_std)

max_p = -INF
# masks = product([-1, 1], repeat=3)
masks = []
for i in [1, -1]:
    for j in [1, -1]:
        for k in [1, -1]:
            masks.append([i, j, k])
# print(masks)
for mask in masks:
    dp = dp_std.copy()
    for i in range(1, N+1):
        score = sum(mul_mask(XYZ[i-1], mask))
        for j in range(1, M+1):
            # print(i, j, XYZ[i-1], mask)
            dp[i][j] = max(
                dp[i-1][j],
                dp[i-1][j-1] + score
            )
            # for dp_i in dp:
            #     print(dp_i)
    p = dp[N][M]
    max_p = max(max_p, p)
    # print(p)

print(max_p)

Buggy submission (verdict: Runtime Error):
# from itertools import product

INF = 10**18

N, M = map(int, input().split())
XYZ = [list(map(int, input().split())) for _ in range(N)]

# i番目までのケーキの内、j個食べた時のpointの最大値
# (ただしpointの計算時には、8通りのmaskを乗算する)

def mul_mask(l, mask):
    return [a*b for a, b in zip(l, mask)]

dp_std = [[-INF for _ in range(M+1)] for _ in range(N+1)]
for i in range(N+1):
    dp_std[i][0] = 0
# print(dp_std)

max_p = -INF
# masks = product([-1, 1], repeat=3)
masks = []
for i in [1, -1]:
    for j in [1, -1]:
        for k in [1, -1]:
            masks.append([i, j, k])
for mask in masks:
    dp = dp_std.copy()
    for i in range(1, N+1):
        score = sum(mul_mask(XYZ[i-1], mask))
        for j in range(1, M+1):
            # print(i, j, XYZ[i-1], mask)
            dp[i][j] = max(
                dp[i-1][j],
                dp[i-1][j-1] + score
            )
            # for dp_i in dp:
            #     print(dp_i)
    p = dp[N][M]
    max_p = max(max_p, p)
    # print(p)

print(max_p)

Buggy submission (verdict: Runtime Error):
# from itertools import product
def product(a, repeat=3):
    for i in a:
        for j in a:
            for k in a:
                yield [i, j, k]

INF = 10**18

N, M = map(int, input().split())
XYZ = [list(map(int, input().split())) for _ in range(N)]

# i番目までのケーキの内、j個食べた時のpointの最大値
# (ただしpointの計算時には、8通りのmaskを乗算する)

def mul_mask(l, mask):
    return [a*b for a, b in zip(l, mask)]

dp_std = [[-INF for _ in range(M+1)] for _ in range(N+1)]
for i in range(N+1):
    dp_std[i][0] = 0
# print(dp_std)

max_p = -INF
for mask in product([-1, 1], repeat=3):
    dp = dp_std.copy()
    for i in range(1, N+1):
        score = sum(mul_mask(XYZ[i-1], mask))
        for j in range(1, M+1):
            # print(i, j, XYZ[i-1], mask)
            dp[i][j] = max(
                dp[i-1][j],
                dp[i-1][j-1] + score
            )
            # for dp_i in dp:
            #     print(dp_i)
    p = dp[N][M]
    max_p = max(max_p, p)
    # print(p)

print(max_p)

Buggy submission (verdict: Runtime Error):
from itertools import product

INF = 10**18

N, M = map(int, input().split())
XYZ = [list(map(int, input().split())) for _ in range(N)]

# i番目までのケーキの内、j個食べた時のpointの最大値
# (ただしpointの計算時には、8通りのmaskを乗算する)

def mul_mask(l, mask):
    return [a*b for a, b in zip(l, mask)]

dp_std = [[-INF for _ in range(M+1)] for _ in range(N+1)]
for i in range(N+1):
    dp_std[i][0] = 0
# print(dp_std)

max_p = -INF
for mask in product([-1, 1], repeat=3):
    dp = dp_std.copy()
    for i in range(1, N+1):
        score = sum(mul_mask(XYZ[i-1], mask))
        for j in range(1, M+1):
            # print(i, j, XYZ[i-1], mask)
            dp[i][j] = max(
                dp[i-1][j],
                dp[i-1][j-1] + score
            )
            # for dp_i in dp:
            #     print(dp_i)
    p = dp[N][M]
    max_p = max(max_p, p)
    # print(p)

print(max_p)