Problem p03078 (python)

Fixed submission:
tmp = list(map(int, input().split()))
x = tmp[0]
y = tmp[1]
z = tmp[2]
k = tmp[3]
a = sorted(list(map(int, input().split())), reverse=True)
b = sorted(list(map(int, input().split())), reverse=True)
c = sorted(list(map(int, input().split())), reverse=True)

ansl = []
for p in range(x):
  if p > k:
    break
  for q in range(y):
    if p * q > k:
      break
    for r in range(z):
      if p * q * r > k:
        break
      ansl.append(a[p] + b[q] + c[r])

ansl.sort(reverse=True)

for i in range(k):
  print(ansl[i])

Buggy submission (verdict: Runtime Error):
import heapq

tmp = list(map(int, input().split()))
x = tmp[0]
y = tmp[1]
z = tmp[2]
k = tmp[3]
a = sorted(list(map(int, input().split())), reverse=True)
b = sorted(list(map(int, input().split())), reverse=True)
c = sorted(list(map(int, input().split())), reverse=True)

#log = [[[False for _ in range(z)] for _ in range(y)] for _ in range(x)]
log = [False] * (x * y * z + 1)
h = []
heapq.heappush(h, (-(a[0]+b[0]+c[0]), 0, 0, 0))
for i in range(k): 
  if len(h) == 0:
    break
  hpop = heapq.heappop(h)
  print(-hpop[0])
  if hpop[1]+1 < x and log[(hpop[1]+1) * y * z + hpop[2] * z + hpop[3]] == False:
    heapq.heappush(h, (-(a[hpop[1]+1]+b[hpop[2]]+c[hpop[3]]), hpop[1]+1, hpop[2], hpop[3]))
    log[(hpop[1]+1) * y * z + hpop[2] * z + hpop[3]] = True
  if hpop[2]+1 < y and log[hpop[1] * y * z + (hpop[2]+1) * z + hpop[3]] == False:
    heapq.heappush(h, (-(a[hpop[1]]+b[hpop[2]+1]+c[hpop[3]]), hpop[1], hpop[2]+1, hpop[3]))
    log[hpop[1] * y * z + (hpop[2]+1) * z + hpop[3]] = True
  if hpop[3]+1 < z and log[hpop[1] * y * z + hpop[2] * z + hpop[3]+1] == False:
    heapq.heappush(h, (-(a[hpop[1]]+b[hpop[2]]+c[hpop[3]+1]), hpop[1], hpop[2], hpop[3]+1))
    log[hpop[1] * y * z + hpop[2] * z + hpop[3]+1] = True

Buggy submission (verdict: Runtime Error):
import heapq

tmp = list(map(int, input().split()))
x = tmp[0]
y = tmp[1]
z = tmp[2]
k = tmp[3]
a = sorted(list(map(int, input().split())), reverse=True)
b = sorted(list(map(int, input().split())), reverse=True)
c = sorted(list(map(int, input().split())), reverse=True)

#log = [[[False for _ in range(z)] for _ in range(y)] for _ in range(x)]
log = [False] * (x * y * z + 1)
h = []
heapq.heappush(h, (-(a[0]+b[0]+c[0]), 0, 0, 0))
for i in range(k): 
  if len(h) == 0:
    break
  tmp = heapq.heappop(h)
  print(-tmp[0])
  if tmp[1]+1 < x and log[(tmp[1]+1) * y * z + tmp[2] * z + tmp[3]] == False:
    heapq.heappush(h, (-(a[tmp[1]+1]+b[tmp[2]]+c[tmp[3]]), tmp[1]+1, tmp[2], tmp[3]))
    log[(tmp[1]+1) * y * z + tmp[2] * z + tmp[3]] = True
  if tmp[2]+1 < y and log[tmp[1] * y * z + (tmp[2]+1) * z + tmp[3]] == False:
    heapq.heappush(h, (-(a[tmp[1]]+b[tmp[2]+1]+c[tmp[3]]), tmp[1], tmp[2]+1, tmp[3]))
    log[tmp[1] * y * z + (tmp[2]+1) * z + tmp[3]] = True
  if tmp[3]+1 < z and log[tmp[1] * y * z + tmp[2] * z + tmp[3]+1] == False:
    heapq.heappush(h, (-(a[tmp[1]]+b[tmp[2]]+c[tmp[3]+1]), tmp[1], tmp[2], tmp[3]+1))
    log[tmp[1] * y * z + tmp[2] * z + tmp[3]+1] = True

Buggy submission (verdict: Runtime Error):
import heapq

tmp = list(map(int, input().split()))
x = tmp[0]
y = tmp[1]
z = tmp[2]
k = tmp[3]
a = sorted(list(map(int, input().split())), reverse=True)
b = sorted(list(map(int, input().split())), reverse=True)
c = sorted(list(map(int, input().split())), reverse=True)

#log = [[[False for _ in range(z)] for _ in range(y)] for _ in range(x)]
log = [False] * x * y * z
h = []
heapq.heappush(h, (-(a[0]+b[0]+c[0]), 0, 0, 0))
for i in range(k): 
  if len(h) == 0:
    break
  tmp = heapq.heappop(h)
  print(-tmp[0])
  if tmp[1]+1 < x and log[(tmp[1]+1) * y * z + tmp[2] * z + tmp[3]] == False:
    heapq.heappush(h, (-(a[tmp[1]+1]+b[tmp[2]]+c[tmp[3]]), tmp[1]+1, tmp[2], tmp[3]))
    log[(tmp[1]+1) * y * z + tmp[2] * z + tmp[3]] = True
  if tmp[2]+1 < y and log[tmp[1] * y * z + (tmp[2]+1) * z + tmp[3]] == False:
    heapq.heappush(h, (-(a[tmp[1]]+b[tmp[2]+1]+c[tmp[3]]), tmp[1], tmp[2]+1, tmp[3]))
    log[tmp[1] * y * z + (tmp[2]+1) * z + tmp[3]] = True
  if tmp[3]+1 < z and log[tmp[1] * y * z + tmp[2] * z + tmp[3]+1] == False:
    heapq.heappush(h, (-(a[tmp[1]]+b[tmp[2]]+c[tmp[3]+1]), tmp[1], tmp[2], tmp[3]+1))
    log[tmp[1] * y * z + tmp[2] * z + tmp[3]+1] = True

Buggy submission (verdict: Runtime Error):
import heapq

tmp = list(map(int, input().split()))
x = tmp[0]
y = tmp[1]
z = tmp[2]
k = tmp[3]
a = sorted(list(map(int, input().split())), reverse=True)
b = sorted(list(map(int, input().split())), reverse=True)
c = sorted(list(map(int, input().split())), reverse=True)

#log = [[[False for _ in range(z)] for _ in range(y)] for _ in range(x)]
log = [False] * x * y * z
h = []
heapq.heappush(h, (-(a[0]+b[0]+c[0]), 0, 0, 0))
for i in range(k): 
  tmp = heapq.heappop(h)
  print(-tmp[0])
  if tmp[1]+1 < x and log[(tmp[1]+1) * y * z + tmp[2] * z + tmp[3]] == False:
    heapq.heappush(h, (-(a[tmp[1]+1]+b[tmp[2]]+c[tmp[3]]), tmp[1]+1, tmp[2], tmp[3]))
    log[(tmp[1]+1) * y * z + tmp[2] * z + tmp[3]] = True
  if tmp[2]+1 < y and log[tmp[1] * y * z + (tmp[2]+1) * z + tmp[3]] == False:
    heapq.heappush(h, (-(a[tmp[1]]+b[tmp[2]+1]+c[tmp[3]]), tmp[1], tmp[2]+1, tmp[3]))
    log[tmp[1] * y * z + (tmp[2]+1) * z + tmp[3]] = True
  if tmp[3]+1 < z and log[tmp[1] * y * z + tmp[2] * z + tmp[3]+1] == False:
    heapq.heappush(h, (-(a[tmp[1]]+b[tmp[2]]+c[tmp[3]+1]), tmp[1], tmp[2], tmp[3]+1))
    log[tmp[1] * y * z + tmp[2] * z + tmp[3]+1] = True

Buggy submission (verdict: Runtime Error):
tmp = list(map(int, input().split()))
x = tmp[0]
y = tmp[1]
z = tmp[2]
k = tmp[3]
a = sorted(list(map(int, input().split())), reverse=True)
b = sorted(list(map(int, input().split())), reverse=True)
c = sorted(list(map(int, input().split())), reverse=True)

log = [[[False for _ in range(z)] for _ in range(y)] for _ in range(x)]

cnt = 0
h = []
heapq.heappush(h, (-(a[0]+b[0]+c[0]), 0, 0, 0))
while len(h) != 0 and cnt < k: 
  tmp = heapq.heappop(h)
  print(-tmp[0])
  cnt += 1
  if tmp[1]+1 < x and log[tmp[1]+1][tmp[2]][tmp[3]] == False:
    heapq.heappush(h, (-(a[tmp[1]+1]+b[tmp[2]]+c[tmp[3]]), tmp[1]+1, tmp[2], tmp[3]))
    log[tmp[1]+1][tmp[2]][tmp[3]] = True
  if tmp[2]+1 < y and log[tmp[1]][tmp[2]+1][tmp[3]] == False:
    heapq.heappush(h, (-(a[tmp[1]]+b[tmp[2]+1]+c[tmp[3]]), tmp[1], tmp[2]+1, tmp[3]))
    log[tmp[1]][tmp[2]+1][tmp[3]] = True
  if tmp[3]+1 < z and log[tmp[1]][tmp[2]][tmp[3]+1] == False:
    heapq.heappush(h, (-(a[tmp[1]]+b[tmp[2]]+c[tmp[3]+1]), tmp[1], tmp[2], tmp[3]+1))
    log[tmp[1]][tmp[2]][tmp[3]+1] = True