Problem p03078 (python)

Fixed submission:
x, y, z, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
a = sorted(a, reverse=True)
b = sorted(b, reverse=True)
c = sorted(c, reverse=True)

q = [(a[0]+b[0]+c[0], 0, 0, 0)]
t = []
next_a = (0,0,0,0)
next_b = (0,0,0,0)
next_c = (0,0,0,0)
for i in range(min(x*y*z, k)):
  m = q.pop(q.index(max(q, key=lambda x: x[0])))
  print(m[0])
  if m[1] < x-1:
    next_a = (a[m[1]+1]+b[m[2]]+c[m[3]], m[1]+1, m[2], m[3])
  if m[2] < y-1:
    next_b = (a[m[1]]+b[m[2]+1]+c[m[3]], m[1], m[2]+1, m[3])
  if m[3] < z-1:
    next_c = (a[m[1]]+b[m[2]]+c[m[3]+1], m[1], m[2], m[3]+1)
  if next_a not in t:
    q.append(next_a)
    t.append(next_a)
  if next_b not in t:
    q.append(next_b)
    t.append(next_b)
  if next_c not in t:
    q.append(next_c)
    t.append(next_c)

Buggy submission (verdict: Runtime Error):
x, y, z, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
a = sorted(a, reverse=True)
b = sorted(b, reverse=True)
c = sorted(c, reverse=True)

q = [(a[0]+b[0]+c[0], 0, 0, 0)]
t = []
for i in range(min(x*y*z, k)):
  m = q.pop(q.index(max(q, key=lambda x: x[0])))
  print(m[0])
  if m[1] < x-1:
    next_a = (a[m[1]+1]+b[m[2]]+c[m[3]], m[1]+1, m[2], m[3])
  if m[2] < y-1:
    next_b = (a[m[1]]+b[m[2]+1]+c[m[3]], m[1], m[2]+1, m[3])
  if m[3] < z-1:
    next_c = (a[m[1]]+b[m[2]]+c[m[3]+1], m[1], m[2], m[3]+1)
  if next_a not in t:
    q.append(next_a)
    t.append(next_a)
  if next_b not in t:
    q.append(next_b)
    t.append(next_b)
  if next_c not in t:
    q.append(next_c)
    t.append(next_c)

Buggy submission (verdict: Runtime Error):
x, y, z, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
a = sorted(a, reverse=True)
b = sorted(b, reverse=True)
c = sorted(c, reverse=True)

q = [(a[0]+b[0]+c[0], 0, 0, 0)]
for i in range(min(x*y*z, k)):
  m = q.pop(q.index(max(q, key=lambda x: x[0])))
  print(m[0])
  if m[1] < x-1:
  	next_a = (a[m[1]+1]+b[m[2]]+c[m[3]], m[1]+1, m[2], m[3])
  if m[2] < y-1:
    next_b = (a[m[1]]+b[m[2]+1]+c[m[3]], m[1], m[2]+1, m[3])
  if m[3] < z-1:
    next_c = (a[m[1]]+b[m[2]]+c[m[3]+1], m[1], m[2], m[3]+1)
  if next_a not in q:
    q.append(next_a)
  if next_b not in q:
    q.append(next_b)
  if next_c not in q:
    q.append(next_c)

Buggy submission (verdict: Runtime Error):
x, y, z, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
a = sorted(a, reverse=True)
b = sorted(b, reverse=True)
c = sorted(c, reverse=True)

q = [(a[0]+b[0]+c[0], 0, 0, 0)]
for i in range(min(x*y*z, k)):
  m = q.pop(q.index(max(q, key=lambda x: x[0])))
  print(m[0])
  next_a = (a[m[1]+1]+b[m[2]]+c[m[3]], m[1]+1, m[2], m[3])
  next_b = (a[m[1]]+b[m[2]+1]+c[m[3]], m[1], m[2]+1, m[3])
  next_c = (a[m[1]]+b[m[2]]+c[m[3]+1], m[1], m[2], m[3]+1)
  if next_a not in q:
    q.append(next_a)
  if next_b not in q:
    q.append(next_b)
  if next_c not in q:
    q.append(next_c)

Buggy submission (verdict: Runtime Error):
x, y, z, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
a = sorted(a, reverse=True)
b = sorted(b, reverse=True)
c = sorted(c, reverse=True)

q = [(a[0]+b[0]+c[0], 0, 0, 0)]
for i in range(k):
  m = q.pop(q.index(max(q, key=lambda x: x[0])))
  print(m[0])
  next_a = (a[m[1]+1]+b[m[2]]+c[m[3]], m[1]+1, m[2], m[3])
  next_b = (a[m[1]]+b[m[2]+1]+c[m[3]], m[1], m[2]+1, m[3])
  next_c = (a[m[1]]+b[m[2]]+c[m[3]+1], m[1], m[2], m[3]+1)
  if next_a not in q:
    q.append(next_a)
  if next_b not in q:
    q.append(next_b)
  if next_c not in q:
    q.append(next_c)