Problem p03326 (python)

Fixed submission:
N,M = list(map(int, input().split()))
cakes = []
for i in range(N):
    cakes.append(list(map(int, input().split())))

ans = 0

for i in range(8):
    values = []
    for cake in cakes:
        value = 0
        for j in range(3):
            if (i >> j) % 2 == 1:
                value -= cake[j]
            else:
                value += cake[j]
        values.append(value)
    values.sort()
    values = values[::-1]
    ans = max(ans, sum(values[:M]))

print(ans)

Buggy submission (verdict: Runtime Error):
N,M = list(map(int, input().split()))
cakes = []
for i in range(N):
    cakes.append(list(map(int, input().split())))

ans = 0

values = []
for cake in cakes:
    value = 0
    for j in range(3):
        values.append(x+y+z)
values.sort()
values = values[::-1]
ans = max(ans, sum(values[:M]))

values = []
for cake in cakes:
    value = 0
    for j in range(3):
        values.append(x+y-z)
values.sort()
values = values[::-1]
ans = max(ans, sum(values[:M]))


values = []
for cake in cakes:
    value = 0
    for j in range(3):
        values.append(x-y+z)
values.sort()
values = values[::-1]
ans = max(ans, sum(values[:M]))


values = []
for cake in cakes:
    value = 0
    for j in range(3):
        values.append(x-y-z)
values.sort()
values = values[::-1]
ans = max(ans, sum(values[:M]))


values = []
for cake in cakes:
    value = 0
    for j in range(3):
        values.append(-x+y+z)
values.sort()
values = values[::-1]
ans = max(ans, sum(values[:M]))


values = []
for cake in cakes:
    value = 0
    for j in range(3):
        values.append(-x+y-z)
values.sort()
values = values[::-1]
ans = max(ans, sum(values[:M]))



values = []
for cake in cakes:
    value = 0
    for j in range(3):
        values.append(-x-y+z)
values.sort()
values = values[::-1]
ans = max(ans, sum(values[:M]))


values = []
for cake in cakes:
    value = 0
    for j in range(3):
        values.append(-x-y-z)
values.sort()
values = values[::-1]
ans = max(ans, sum(values[:M]))


print(ans)

Buggy submission (verdict: Runtime Error):
N,M = list(map(int, input().split()))
cakes = []
for i in range(N):
    cakes.append(list(map(int, input().split())))

ans = 0

for cake in cakes:
    value = 0
    for j in range(3):
        values.append(x+y+z)
values.sort()
values = values[::-1]
ans = max(ans, sum(values[:M]))

values = []
for cake in cakes:
    value = 0
    for j in range(3):
        values.append(x+y-z)
values.sort()
values = values[::-1]
ans = max(ans, sum(values[:M]))


values = []
for cake in cakes:
    value = 0
    for j in range(3):
        values.append(x-y+z)
values.sort()
values = values[::-1]
ans = max(ans, sum(values[:M]))


values = []
for cake in cakes:
    value = 0
    for j in range(3):
        values.append(x-y-z)
values.sort()
values = values[::-1]
ans = max(ans, sum(values[:M]))


values = []
for cake in cakes:
    value = 0
    for j in range(3):
        values.append(-x+y+z)
values.sort()
values = values[::-1]
ans = max(ans, sum(values[:M]))


values = []
for cake in cakes:
    value = 0
    for j in range(3):
        values.append(-x+y-z)
values.sort()
values = values[::-1]
ans = max(ans, sum(values[:M]))



values = []
for cake in cakes:
    value = 0
    for j in range(3):
        values.append(-x-y+z)
values.sort()
values = values[::-1]
ans = max(ans, sum(values[:M]))


values = []
for cake in cakes:
    value = 0
    for j in range(3):
        values.append(-x-y-z)
values.sort()
values = values[::-1]
ans = max(ans, sum(values[:M]))


print(ans)