Problem p03078 (python)

Fixed submission:
from heapq import *

X, Y, Z, K = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]
A = sorted([int(x) for x in A], reverse=True)
B = sorted([int(x) for x in B], reverse=True)
C = sorted([int(x) for x in C], reverse=True)

res = []
memo = []
ans = []
heappush(res, (-A[0]-B[0]-C[0], 0, 0, 0))
while len(ans) < K:
  e, i, j, k = heappop(res)
  ans.append(-e)
  if i+1 < X and [i+1, j, k] not in memo:
    heappush(res, (-A[i+1]-B[j]-C[k], i+1, j, k))
    memo.append([i+1, j, k])
  if j+1 < Y and [i, j+1, k] not in memo:
    heappush(res, (-A[i]-B[j+1]-C[k], i, j+1, k))
    memo.append([i, j+1, k])
  if k+1 < Z and [i, j, k+1] not in memo:
    heappush(res, (-A[i]-B[j]-C[k+1], i, j, k+1))
    memo.append([i, j, k+1])

for i in ans:
  print(i)

Buggy submission (verdict: Runtime Error):
X, Y, Z, K = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]
A = sorted([int(x) for x in A], reverse=True)
B = sorted([int(x) for x in B], reverse=True)
C = sorted([int(x) for x in C], reverse=True)

res = []
memo = []
i, j, k = 0, 0, 0
while len(res) < K:
  if [i, j, k] not in memo:
    res.append(A[i]+B[j]+C[k])
    memo.append([i,j,k])
  if i+1 < X and [i+1, j, k] not in memo:
    res.append(A[i+1]+B[j]+C[k])
    memo.append([i+1, j, k])
  if j+1 < Y and [i, j+1, k] not in memo:
    res.append(A[i]+B[j+1]+C[k])
    memo.append([i, j+1, k])
  if k+1 < Z and [i, j, k+1] not in memo:
    res.append(A[i]+B[j]+C[k+1])
    memo.append([i, j, k+1])
  if i < X:
    i += 1
  if j < Y:
    j += 1
  if k < Z:
    k += 1
res = sorted(res, reverse=True)[:K]
for i in res:
  print(i)

Buggy submission (verdict: Runtime Error):
X, Y, Z, K = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]
A = sorted([int(x) for x in A], reverse=True)
B = sorted([int(x) for x in B], reverse=True)
C = sorted([int(x) for x in C], reverse=True)

res = []
memo = []
i, j, k = 0, 0, 0
while len(res) < K:
  if [i, j, k] not in memo:
  	res.append(A[i]+B[j]+C[k])
    memo.append([i,j,k])
  if i+1 < X and [i+1, j, k] not in memo:
  	res.append(A[i+1]+B[j]+C[k])
    memo.append([i+1, j, k])
  if j+1 < Y and [i, j+1, k[ not in memo:
  	res.append(A[i]+B[j+1]+C[k])
    memo.append([i, j+1, k])
  if k+1 < Z and [i, j, k+1] not in memo:
  	res.append(A[i]+B[j]+C[k+1])
    memo.append([i, j, k+1])
  if i < X:
    i += 1
  if j < Y:
    j += 1
  if k < Z:
    k += 1
res = sorted(res, reverse=True)[:K]
for i in res:
  print(i)

Buggy submission (verdict: Runtime Error):
X, Y, Z, K = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]
A = sorted([int(x) for x in A], reverse=True)
B = sorted([int(x) for x in B], reverse=True)
C = sorted([int(x) for x in C], reverse=True)

res = []
memo = []
i, j, k = 0, 0, 0
while len(res) < K:
  if (i, j, k) not in memo:
  	res.append(A[i]+B[j]+C[k])
    memo.append((i,j,k))
  if i+1 < X and (i+1, j, k) not in memo:
  	res.append(A[i+1]+B[j]+C[k])
    memo.append((i+1, j, k))
  if j+1 < Y and (i, j+1, k) not in memo:
  	res.append(A[i]+B[j+1]+C[k])
    memo.append((i, j+1, k))
  if k+1 < Z and (i, j, k+1) not in memo:
  	res.append(A[i]+B[j]+C[k+1])
    memo.append((i, j, k+1))
  if i < X:
    i += 1
  if j < Y:
    j += 1
  if k < Z:
    k += 1
res = sorted(res, reverse=True)[:K]
for i in res:
  print(i)

Buggy submission (verdict: Runtime Error):
X, Y, Z, K = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]
A = sorted([int(x) for x in A], reverse=True)
B = sorted([int(x) for x in B], reverse=True)
C = sorted([int(x) for x in C], reverse=True)

res = []
i, j, k = 0, 0, 0
while len(res) < K:
  res.append(A[i]+B[j]+C[k])
  if i+1 < X:
  	res.append(A[i+1]+B[j]+C[k])
  if j+1 < Y:
  	res.append(A[i]+B[j+1]+C[k])
  if k+1 < Z:
  	res.append(A[i]+B[j]+C[k+1])
  if i < X:
    i += 1
  if j < Y:
    j += 1
  if k < Z:
    k += 1
res = sorted(res, reverse=True)[:K]
for i in res:
  print(i)

Buggy submission (verdict: Runtime Error):
X, Y, Z, K = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]
A = sorted([int(x) for x in A], reverse=True)
B = sorted([int(x) for x in B], reverse=True)
C = sorted([int(x) for x in C], reverse=True)

res = []
i, j, k = 0, 0, 0
while len(res) < K:
  res.append(A[i]+B[j]+C[k])
  res.append(A[i+1]+B[j]+C[k])
  res.append(A[i]+B[j+1]+C[k])
  res.append(A[i]+B[j]+C[k+1])
  if i < X:
    i += 1
  if j < Y:
    j += 1
  if k < Z:
    k += 1
res = sorted(res, reverse=True)[:K]
for i in res:
  print(i)

Buggy submission (verdict: Runtime Error):
X, Y, Z, K = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]
A = sorted([int(x) for x in A], reverse=True)
B = sorted([int(x) for x in B], reverse=True)
C = sorted([int(x) for x in C], reverse=True)

res = []
i, j, k = 0, 0, 0
while len(res) < K:
  res.append(A[i]+B[j]+C[k])
  res.append(A[i+1]+B[j]+C[k])
  res.append(A[i]+B[j+1]+C[k])
  res.append(A[i]+B[j]+C[k+1])
  i,j,k = i+1, j+1, k+1
res = sorted(res, reverse=True)[:K]
for i in res:
  print(i)

Buggy submission (verdict: Runtime Error):
X, Y, Z, K = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]
A = sorted([int(x) for x in A], reversed=True)
B = sorted([int(x) for x in B], reversed=True)
C = sorted([int(x) for x in C], reversed=True)

res = []
i, j, k = 0, 0, 0
while len(res) < K:
  res.append(A[i]+B[j]+C[k])
  res.append(A[i+1]+B[j]+C[k])
  res.append(A[i]+B[j+1]+C[k])
  res.append(A[i]+B[j]+C[k+1])
  i,j,k = i+1, j+1, k+1
res = sorted(res, reversed=True)[:K]
for i in res:
  print(i)

Buggy submission (verdict: Runtime Error):
line = input()
K = int(line.split(' ')[-1])
A = input().split(' ')
B = input().split(' ')
C = input().split(' ')
A = sorted([int(x) for x in A], reversed=True)
B = sorted([int(x) for x in B], reversed=True)
C = sorted([int(x) for x in C], reversed=True)

res = []
i, j, k = 0, 0, 0
while len(res) < K:
  res.append(A[i]+B[j]+C[k])
  res.append(A[i+1]+B[j]+C[k])
  res.append(A[i]+B[j+1]+C[k])
  res.append(A[i]+B[j]+C[k+1])
  i,j,k = i+1, j+1, k+1
res = sorted(res, reversed=True)[:K]
for i in res:
  print(i)

Buggy submission (verdict: Runtime Error):
a,b,c,K = int(input()),int(input()),int(input()),int(input())
A = input().split(' ')
B = input().split(' ')
C = input().split(' ')
A = sorted([int(x) for x in A], reversed=True)
B = sorted([int(x) for x in B], reversed=True)
C = sorted([int(x) for x in C], reversed=True)

res = []
i, j, k = 0, 0, 0
while len(res) < K:
  res.append(A[i]+B[j]+C[k])
  res.append(A[i+1]+B[j]+C[k])
  res.append(A[i]+B[j+1]+C[k])
  res.append(A[i]+B[j]+C[k+1])
  i,j,k = i+1, j+1, k+1
res = sorted(res, reversed=True)[:K]
for i in res:
  print(i)

Buggy submission (verdict: Runtime Error):
a,b,c,K = int(input()),int(input()),int(input()),int(input())
A = sorted([int(x) for x in input().split(' ')], reversed=True)
B = sorted([int(x) for x in input().split(' ')], reversed=True)
C = sorted([int(x) for x in input().split(' ')], reversed=True)

res = []
i, j, k = 0, 0, 0
while len(res) < K:
  res.append(A[i]+B[j]+C[k])
  res.append(A[i+1]+B[j]+C[k])
  res.append(A[i]+B[j+1]+C[k])
  res.append(A[i]+B[j]+C[k+1])
  i,j,k = i+1, j+1, k+1
res = sorted(res, reversed=True)[:K]
for i in res:
  print(i)

Buggy submission (verdict: Runtime Error):
from heapq import *

a,b,c,K = int(input()),int(input()),int(input()),int(input())
A = sorted([int(x) for x in input().split(' ')], reversed=True)
B = sorted([int(x) for x in input().split(' ')], reversed=True)
C = sorted([int(x) for x in input().split(' ')], reversed=True)

res = []
i, j, k = 0, 0, 0
while len(res) < K:
  res.append(A[i]+B[j]+C[k])
  res.append(A[i+1]+B[j]+C[k])
  res.append(A[i]+B[j+1]+C[k])
  res.append(A[i]+B[j]+C[k+1])
  i,j,k = i+1, j+1, k+1
res = sorted(res, reversed=True)[:K]
for i in res:
  print(i)

Buggy submission (verdict: Runtime Error):
from heapq import *

a,b,c,K = int(input()),int(input()),int(input()),int(input())
A = sorted([int(x) for x in input().split(' ')], reversed=True)
B = sorted([int(x) for x in input().split(' ')], reversed=True)
C = sorted([int(x) for x in input().split(' ')], reversed=True)

res = []
i, j, k = 0, 0, 0
while len(res) < K:
  heappush(res, A[i]+B[j]+C[k])
  heappush(res, A[i+1]+B[j]+C[k])
  heappush(res, A[i]+B[j+1]+C[k])
  heappush(res, A[i]+B[j]+C[k+1])
  i,j,k = i+1, j+1, k+1
res = nlargest(K, res)
for i in res:
  print(i)

Buggy submission (verdict: Runtime Error):
from heapq import *

a,b,c,K = int(input()),int(input()),int(input()),int(input())
A = sorted([int(x) for x in input().split(' ')], reversed=True)
B = sorted([int(x) for x in input().split(' ')], reversed=True)
C = sorted([int(x) for x in input().split(' ')], reversed=True)

res = []
i, j, k = 0, 0, 0
while len(res) < K:
  heappush(res, A[i]+B[j]+C[k])
  heappush(res, A[i+1]+B[j]+C[k])
  heappush(res, A[i]+B[j+1]+C[k])
  heappush(res, A[i]+B[j]+C[k+1])
  i,j,k = i+1, j+1, k+1
res = nlargeest(K, res)
for i in res:
  print(i)

Buggy submission (verdict: Runtime Error):
from heapq import *

a,b,c,K = int(input()),int(input()),int(input()),int(input())
A = sorted([int(x) for x in input().split(' ')], reversed=True)
B = sorted([int(x) for x in input().split(' ')], reversed=True)
C = sorted([int(x) for x in input().split(' ')], reversed=True)

res = []
i, j, k = 0, 0, 0
while len(res) < K:
  heappush(res, A[i]+B[j]+C[k])
  heappush(res, A[i+1]+B[j]+C[k])
  heappush(res, A[i]+B[j+1]+C[k])
  heappush(res, A[i]+B[j]+C[k+1])
res = nlargeest(K, res)
for i in res:
  print(i)