input
stringlengths
20
127k
target
stringlengths
20
119k
problem_id
stringlengths
6
6
import heapq,sys def main(): input = sys.stdin.readline X, Y, Z, K = list(map(int, input().split())) A = sorted([int(i) for i in input().split()], reverse=True) B = sorted([int(i) for i in input().split()], reverse=True) C = sorted([int(i) for i in input().split()], reverse=True) ans = [] heap_queue = [] for i in range(X): for j in range(Y): for k in range(Z): heapq.heappush(heap_queue, A[i] + B[j] + C[k]) #要素がK個以上ならはじく!!!ことでO(logK) if len(heap_queue) > K: heapq.heappop(heap_queue) heap_queue.sort(reverse = True) for e in heap_queue: print(e) if __name__ == '__main__': main()
import heapq,sys def main(): input = sys.stdin.readline X, Y, Z, K = list(map(int, input().split())) A = list(map(int,input().split())) B = list(map(int,input().split())) C = list(map(int,input().split())) #A+Bでのベスト枠K個求めるO(XYlogK) AandB = [] for i in range(X): for j in range(Y): heapq.heappush(AandB, A[i] + B[j]) #要素がK+1個以上なら一々はじく!!!ことでO(logK) if len(AandB) > K: heapq.heappop(AandB) #上のとCでのベスト枠K個を求める(ZKlogK) heap_queue = [] for p in range(Z): for h in range(len(AandB)): heapq.heappush(heap_queue,C[p] + AandB[h]) if len(heap_queue) > K: heapq.heappop(heap_queue) heap_queue.sort(reverse = True) for e in heap_queue: print(e) if __name__ == '__main__': main()
p03078
import heapq,sys def main(): input = sys.stdin.readline X, Y, Z, K = list(map(int, input().split())) A = list(map(int,input().split())) B = list(map(int,input().split())) C = list(map(int,input().split())) #A+Bでのベスト枠K個求めるO(XYlogK) AandB = [] for i in range(X): for j in range(Y): heapq.heappush(AandB, A[i] + B[j]) #要素がK+1個以上なら一々はじく!!!ことでO(logK) if len(AandB) > K: heapq.heappop(AandB) #上のとCでのベスト枠K個を求める(ZKlogK) heap_queue = [] for p in range(Z): for h in range(len(AandB)): heapq.heappush(heap_queue,C[p] + AandB[h]) if len(heap_queue) > K: heapq.heappop(heap_queue) heap_queue.sort(reverse = True) for e in heap_queue: print(e) if __name__ == '__main__': main()
import heapq,sys def main(): input = sys.stdin.readline X, Y, Z, K = list(map(int, input().split())) A = list(map(int,input().split())) B = list(map(int,input().split())) C = list(map(int,input().split())) #A+Bでのベスト枠K個求めるO(XYlogK) AandB = [] for x in A: for y in B: heapq.heappush(AandB,x+y) #要素がK+1個以上なら一々はじく!!!ことでO(logK) if len(AandB) > K: heapq.heappop(AandB) #上のとCでのベスト枠K個を求める(ZKlogK) heap_queue = [] for z in C: for elt in AandB: heapq.heappush(heap_queue,z+elt) if len(heap_queue) > K: heapq.heappop(heap_queue) heap_queue.sort(reverse = True) for e in heap_queue: print(e) if __name__ == '__main__': main()
p03078
import bisect X, Y, X, K = list(map(int, 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.sort() B.sort() C.sort() ans1 = [] ans2 = [] for i in range(min(K,len(A))): for j in range(min(K,len(B))): ans1.append(A[i]+B[j]) ans1.sort(reverse=True) for i in range(min(K,len(ans1))): for k in range(min(K,len(C))): ans2.append(ans1[i]+C[k]) ans2.sort(reverse=True) for i in range(K): print((ans2[i]))
from heapq import heappop, heappush X, Y, X, K = list(map(int, 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.sort(reverse=True) B.sort(reverse=True) C.sort(reverse=True) Q = [] heappush(Q,[-1*(A[0]+B[0]+C[0]),(0,0,0)]) memo = [(0,0,0)] i,j,k = 0,0,0 for i in range(K): ans,(i,j,k) = heappop(Q) print((-ans)) if (i+1,j,k) not in memo and i+1 < len(A): heappush(Q,[-1*(A[i+1]+B[j]+C[k]),(i+1,j,k)]) memo.append((i+1,j,k)) if (i,j+1,k) not in memo and j+1 < len(B): heappush(Q,[-1*(A[i]+B[j+1]+C[k]),(i,j+1,k)]) memo.append((i,j+1,k)) if (i,j,k+1) not in memo and k+1 < len(C): heappush(Q,[-1*(A[i]+B[j]+C[k+1]),(i,j,k+1)]) memo.append((i,j,k+1))
p03078
X, Y, Z, K = list(map(int, input().split())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) tmp = [] for a in A: for b in B: tmp.append(a + b) ans = [] for ab in tmp: for c in C: ans.append(ab + c) ans.sort(reverse=True) for i in range(K): print((ans[i]))
X, Y, Z, K = list(map(int, input().split())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) # A+Bの上位K個 tmp = [] for a in A: for b in B: tmp.append(a + b) tmp.sort(reverse=True) tmp = tmp[:K] ans = [] for ab in tmp: for c in C: ans.append(ab + c) ans.sort(reverse=True) for i in range(K): print((ans[i]))
p03078
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left, insort, insort_left from heapq import heappush, heappop from functools import reduce, lru_cache def input(): return sys.stdin.readline().strip() def INT(): return int(input()) def MAP(): return map(int, input().split()) def LIST(): return list(map(int, input().split())) def TUPLE(): return tuple(map(int, input().split())) def ZIP(n): return zip(*(MAP() for _ in range(n))) sys.setrecursionlimit(10 ** 9) INF = float('inf') mod = 10 ** 9 + 7 #mod = 998244353 from decimal import * #import numpy as np #decimal.getcontext().prec = 10 X, Y, Z, K = MAP() A = sorted(LIST(), reverse = True) B = sorted(LIST(), reverse = True) C = sorted(LIST(), reverse = True) AB = [] for i in range(X): for j in range(Y): AB.append(A[i]+B[j]) AB.sort(reverse = True) AB = AB[:3000] ABC = sorted([C[0]+AB[i] for i in range(min(3000, X*Y))], reverse = True) for j in range(1, Z): ABC_tmp = sorted([C[j]+AB[i] for i in range(min(3000, X*Y))]) ABC += ABC_tmp ABC.sort(reverse = True) ABC = ABC[:3000] print(*ABC[:K], sep= "\n")
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left, insort, insort_left from heapq import heappush, heappop from functools import reduce, lru_cache def input(): return sys.stdin.readline().strip() def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(): return list(map(int, input().split())) def TUPLE(): return tuple(map(int, input().split())) def ZIP(n): return list(zip(*(MAP() for _ in range(n)))) sys.setrecursionlimit(10 ** 9) INF = float('inf') mod = 10 ** 9 + 7 #mod = 998244353 from decimal import * #import numpy as np #decimal.getcontext().prec = 10 X, Y, Z, K = MAP() A = sorted(LIST(), reverse = True) B = sorted(LIST(), reverse = True) C = sorted(LIST(), reverse = True) ans = [] for i in range(X): for j in range(Y): for k in range(Z): if (i+1)*(j+1)*(k+1) <= K: ans.append(A[i]+B[j]+C[k]) else: break for a in sorted(ans)[::-1][:K]: print(a)
p03078
X, Y, Z, K = list(map(int, input().split())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) A.sort(reverse=True) B.sort(reverse=True) C.sort(reverse=True) AB = [] for a in A: for b in B: AB.append(a + b) AB.sort(reverse=True) AB = AB[:min(3001, X * Y * Z + 1)] ABC = [] for ab in AB: for c in C: ABC.append(ab + c) ABC.sort(reverse=True) for i in range(K): print((ABC[i]))
X, Y, Z, K = list(map(int, input().split())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) A.sort(reverse=True) B.sort(reverse=True) C.sort(reverse=True) AB = [] for a in A: for b in B: AB.append(a + b) AB.sort(reverse=True) AB = AB[:min(3001, X * Y * Z + 1)] ABC = [] for c in C: for ab in AB: ABC.append(ab + c) ABC.sort(reverse=True) for i in range(K): print((ABC[i]))
p03078
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.sort(reverse=True) B.sort(reverse=True) C.sort(reverse=True) AB = [] for a in A: for b in B: AB.append(a + b) AB.sort(reverse=True) AB = AB[:min(3001, X * Y * Z + 1)] ABC = [] for c in C: for ab in AB: ABC.append(ab + c) ABC.sort(reverse=True) print(*ABC[:K], sep='\n')
X, Y, Z, K = list(map(int, input().split())) 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) AB = [] for a in A: for b in B: AB.append(a + b) AB.sort(reverse=True) AB = AB[:min(3001, X * Y * Z + 1)] ABC = [] for c in C: for ab in AB: ABC.append(ab + c) ABC.sort(reverse=True) for i in range(K): print((ABC[i]))
p03078
X,Y,Z,K = list(map(int,input().split())) A = list(map(int,input().split())) B = list(map(int,input().split())) C = list(map(int,input().split())) AB=[] A.sort(reverse=True) A = A[0:K] B.sort(reverse=True) B = B[0:K] for a in A: for b in B: AB.append(a+b) AB.sort(reverse=True) AB = AB[0:K] ABC=[] C.sort(reverse=True) C=C[0:K] for ab in AB: for c in C: ABC.append(ab+c) ABC.sort(reverse=True) for i in range(K): print((ABC[i]))
X,Y,Z,K = list(map(int,input().split())) A = list(map(int,input().split())) B = list(map(int,input().split())) C = list(map(int,input().split())) A.sort(reverse=True) A = A[0:K] B.sort(reverse=True) B = B[0:K] AB = [a+b for a in A for b in B] AB.sort(reverse=True) AB = AB[0:K] C.sort(reverse=True) C=C[0:K] ABC = [ab+c for ab in AB for c in C] ABC.sort(reverse=True) for i in range(K): print((ABC[i]))
p03078
def main(): X,Y,Z,k=list(map(int,input().split())) a=list(map(int,input().split())) b=list(map(int,input().split())) c=list(map(int,input().split())) ab=[] for x in a: for y in b: ab.append(x+y) ab.sort(reverse=True) if len(ab)>k: ab=ab[:k+1] c.sort() l=0 r=max(ab)+max(c)+1 import bisect while r-l>1: cnt=0 mid=(l+r)//2 for x in ab: cnt+=Z-bisect.bisect_left(c,mid-x) if cnt>=k: l=mid else: r=mid ans=[] for i in range(len(ab)): for j in range(bisect.bisect_left(c,l-ab[i]),Z): ans.append(ab[i]+c[j]) ans.sort(reverse=True) for i in range(min(k,len(ans))): print((ans[i])) if __name__=="__main__": main()
x,y,z,k=list(map(int,input().split())) a=list(map(int,input().split())) b=list(map(int,input().split())) c=list(map(int,input().split())) a.sort(reverse=True) b.sort(reverse=True) c.sort(reverse=True) ans=[] for i in range(min(x,k+1)): for j in range(y): if (i+1)*(j+1)>k: break for l in range(z): if (i+1)*(j+1)*(l+1)<=k: ans.append(a[i]+b[j]+c[l]) else: break ans.sort() for i in range(k): print((ans[-i-1]))
p03078
import heapq X,Y,Z,K=list(map(int,input().split())) A=list(map(int,input().split())) B=list(map(int,input().split())) C=list(map(int,input().split())) AB=[] for i in A: for j in B: heapq.heappush(AB,-i-j) #print(AB) ABC=[] for i in AB: for j in C: heapq.heappush(ABC,i-j) for i in range(min(K,X*Y*Z)): print((-heapq.heappop(ABC)))
import heapq X,Y,Z,K=list(map(int,input().split())) A=list(map(int,input().split())) B=list(map(int,input().split())) C=list(map(int,input().split())) AB=[] for i in A: for j in B: heapq.heappush(AB,-i-j) #print(AB) ABC=[] for i in range(min(K,X*Y)): temp=heapq.heappop(AB) for j in C: heapq.heappush(ABC,temp-j) for i in range(min(K,X*Y*Z)): print((-heapq.heappop(ABC)))
p03078
import heapq X,Y,Z,K=list(map(int,input().split())) A=list(map(int,input().split())) B=list(map(int,input().split())) C=list(map(int,input().split())) AB=[] for i in A: for j in B: heapq.heappush(AB,-i-j) #print(AB) ABC=[] for i in range(min(K,X*Y)): temp=heapq.heappop(AB) for j in C: heapq.heappush(ABC,temp-j) for i in range(min(K,X*Y*Z)): print((-heapq.heappop(ABC)))
X, Y, Z, K = list(map(int, input().split())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) A.sort(reverse = True) B.sort(reverse = True) C.sort(reverse = True) AB = [] for a in A: for b in B: AB.append(a + b) AB.sort(reverse = True) AB = AB[:3000] ABC = [] for ab in AB: for c in C: ABC.append(ab + c) ABC.sort(reverse = True) for i in range(K): print((ABC[i]))
p03078
x,y,z,k = list(map(int, input().split())) a= list(map(int, input().split())) b= list(map(int, input().split())) c= list(map(int, input().split())) a.sort(reverse=True) b.sort(reverse=True) c.sort(reverse=True) ansListab=[] for i in range(x): for j in range(y): ansListab.append(a[i]+b[j]) ansListab.sort(reverse= True) ansListab=ansListab[:min(3001,x*y*z+1)] ansList=[] for i in c: for j in ansListab: ansList.append(i+j) ansList.sort(reverse= True) for i in range(k): print((ansList[i]))
x,y,z,k = list(map(int, input().split())) a= list(map(int, input().split())) b= list(map(int, input().split())) c= list(map(int, input().split())) a.sort(reverse=True) b.sort(reverse=True) c.sort(reverse=True) ansListab=[] for i in range(x): for j in range(y): ansListab.append(a[i]+b[j]) ansListab.sort(reverse= True) if len(ansListab)>k: ansListab=ansListab[0:k] ansList=[] for i in c: for j in ansListab: ansList.append(i+j) ansList.sort(reverse= True) for i in range(k): print((ansList[i]))
p03078
#!/usr/bin/env python3 import sys def solve(X: int, Y: int, Z: int, K: int, A: "List[int]", B: "List[int]", C: "List[int]"): # A.sort(reverse=True) # B.sort(reverse=True) AB = [] for a in A: for b in B: AB.append(a+b) AB.sort(reverse=True) C.sort(reverse=True) AB = AB[:K] C = C[:K] ABC = [] for ab in AB: for c in C: ABC.append(ab+c) ABC.sort(reverse=True) for i in range(K): print((ABC[i])) return # Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template) def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() X = int(next(tokens)) # type: int Y = int(next(tokens)) # type: int Z = int(next(tokens)) # type: int K = int(next(tokens)) # type: int A = [int(next(tokens)) for _ in range(X)] # type: "List[int]" B = [int(next(tokens)) for _ in range(Y)] # type: "List[int]" C = [int(next(tokens)) for _ in range(Z)] # type: "List[int]" solve(X, Y, Z, K, A, B, C) if __name__ == '__main__': main()
#!/usr/bin/env python3 import sys def solve(X: int, Y: int, Z: int, K: int, A: "List[int]", B: "List[int]", C: "List[int]"): AB = [] for a in A: for b in B: AB.append(a+b) AB.sort(reverse=True) C.sort(reverse=True) AB = AB[:K] C = C[:K] ABC = [] for ab in AB: for c in C: ABC.append(ab+c) ABC.sort(reverse=True) for i in range(K): print((ABC[i])) return # Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template) def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() X = int(next(tokens)) # type: int Y = int(next(tokens)) # type: int Z = int(next(tokens)) # type: int K = int(next(tokens)) # type: int A = [int(next(tokens)) for _ in range(X)] # type: "List[int]" B = [int(next(tokens)) for _ in range(Y)] # type: "List[int]" C = [int(next(tokens)) for _ in range(Z)] # type: "List[int]" solve(X, Y, Z, K, A, B, C) if __name__ == '__main__': main()
p03078
#!/usr/bin/env python3 import sys def solve(X: int, Y: int, Z: int, K: int, A: "List[int]", B: "List[int]", C: "List[int]"): import heapq A.sort(reverse=True) B.sort(reverse=True) C.sort(reverse=True) h = [] heapq.heappush(h, [-(A[0]+B[0]+C[0]), 0, 0, 0]) ans = [] used = [[[False for _ in range(K)] for _ in range(K)] for _ in range(K)] used[0][0][0] = True for _ in range(K): e, i, j, k = heapq.heappop(h) ans.append(-e) if i+1 < X and not used[i+1][j][k]: used[i+1][j][k] = True heapq.heappush(h, [-(A[i+1]+B[j]+C[k]), i+1, j, k]) if j+1 < Y and not used[i][j+1][k]: used[i][j+1][k] = True heapq.heappush(h, [-(A[i]+B[j+1]+C[k]), i, j+1, k]) if k+1 < Z and not used[i][j][k+1]: used[i][j][k+1] = True heapq.heappush(h, [-(A[i]+B[j]+C[k+1]), i, j, k+1]) for elem in ans: print(elem) #def solve(X: int, Y: int, Z: int, K: int, A: "List[int]", B: "List[int]", C: "List[int]"): # AB = [] # for a in A: # for b in B: # AB.append(a+b) # AB.sort(reverse=True) # C.sort(reverse=True) # AB = AB[:K] # C = C[:K] # ABC = [] # for ab in AB: # for c in C: # ABC.append(ab+c) # ABC.sort(reverse=True) # for i in range(K): # print(ABC[i]) # return # Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template) def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() X = int(next(tokens)) # type: int Y = int(next(tokens)) # type: int Z = int(next(tokens)) # type: int K = int(next(tokens)) # type: int A = [int(next(tokens)) for _ in range(X)] # type: "List[int]" B = [int(next(tokens)) for _ in range(Y)] # type: "List[int]" C = [int(next(tokens)) for _ in range(Z)] # type: "List[int]" solve(X, Y, Z, K, A, B, C) if __name__ == '__main__': main()
#!/usr/bin/env python3 import sys def solve(X: int, Y: int, Z: int, K: int, A: "List[int]", B: "List[int]", C: "List[int]"): import heapq A.sort(reverse=True) B.sort(reverse=True) C.sort(reverse=True) h = [] heapq.heappush(h, [-(A[0]+B[0]+C[0]), 0, 0, 0]) ans = [] used = set() used.add((0, 0, 0)) for _ in range(K): e, i, j, k = heapq.heappop(h) ans.append(-e) if i+1 < X and not (i+1, j, k) in used: used.add((i+1, j, k)) heapq.heappush(h, [-(A[i+1]+B[j]+C[k]), i+1, j, k]) if j+1 < Y and not (i, j+1, k) in used: used.add((i, j+1, k)) heapq.heappush(h, [-(A[i]+B[j+1]+C[k]), i, j+1, k]) if k+1 < Z and not (i, j, k+1) in used: used.add((i, j, k+1)) heapq.heappush(h, [-(A[i]+B[j]+C[k+1]), i, j, k+1]) for elem in ans: print(elem) #def solve(X: int, Y: int, Z: int, K: int, A: "List[int]", B: "List[int]", C: "List[int]"): # AB = [] # for a in A: # for b in B: # AB.append(a+b) # AB.sort(reverse=True) # C.sort(reverse=True) # AB = AB[:K] # C = C[:K] # ABC = [] # for ab in AB: # for c in C: # ABC.append(ab+c) # ABC.sort(reverse=True) # for i in range(K): # print(ABC[i]) # return # Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template) def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() X = int(next(tokens)) # type: int Y = int(next(tokens)) # type: int Z = int(next(tokens)) # type: int K = int(next(tokens)) # type: int A = [int(next(tokens)) for _ in range(X)] # type: "List[int]" B = [int(next(tokens)) for _ in range(Y)] # type: "List[int]" C = [int(next(tokens)) for _ in range(Z)] # type: "List[int]" solve(X, Y, Z, K, A, B, C) if __name__ == '__main__': main()
p03078
x, y, z, k = list(map(int, input().split(' '))) a = list(map(int, input().split(' '))) b = list(map(int, input().split(' '))) c = list(map(int, input().split(' '))) a.sort(reverse=True) b.sort(reverse=True) c.sort(reverse=True) t = [] for i in set(range(x)): for j in set(range(y)): for l in set(range(z)): if (i+1) * (j+1) * (l+1) <= k: t.append(a[i]+b[j]+c[l]) else: break t.sort(reverse=True) for i in range(k): print((t[i]))
x,y,z,K=list(map(int,input().split())) a=list(map(int,input().split())) b=list(map(int,input().split())) c=list(map(int,input().split())) a.sort(reverse=True) b.sort(reverse=True) c.sort(reverse=True) ans=[] for i in range(x): for j in range(y): for k in range(z): if (i+1)*(j+1)*(k+1)<=K: ans.append(a[i]+b[j]+c[k]) else: break ans.sort(reverse=True) for i in range(K): print((ans[i]))
p03078
from heapq import heappush, heappop X, Y, Z, K = list(map(int, input().split())) A = [int(s) for s in input().split()] B = [int(s) for s in input().split()] C = [int(s) for s in input().split()] A.sort(reverse=True) B.sort(reverse=True) C.sort(reverse=True) h = [] maxv = A[0] + B[0] + C[0] def inv(v): return maxv - v pushed = [[[False] * Z for _ in range(Y)] for _ in range(X)] heappush(h, (0, 0, 0, 0)) for _ in range(K): invv, i, j, k = heappop(h) print((inv(invv))) if i + 1 < X and not pushed[i + 1][j][k]: heappush(h, (inv(A[i + 1] + B[j] + C[k]), i + 1, j, k)) pushed[i + 1][j][k] = True if j + 1 < Y and not pushed[i][j + 1][k]: heappush(h, (inv(A[i] + B[j + 1] + C[k]), i, j + 1, k)) pushed[i][j + 1][k] = True if k + 1 < Z and not pushed[i][j][k + 1]: heappush(h, (inv(A[i] + B[j] + C[k + 1]), i, j, k + 1)) pushed[i][j][k + 1] = True
from heapq import heappush, heappop X, Y, Z, K = list(map(int, input().split())) A = [int(s) for s in input().split()] B = [int(s) for s in input().split()] C = [int(s) for s in input().split()] A.sort(reverse=True) B.sort(reverse=True) C.sort(reverse=True) h = [] maxv = A[0] + B[0] + C[0] def inv(v): return maxv - v pushed = [] heappush(h, (0, 0, 0, 0)) for _ in range(K): invv, i, j, k = heappop(h) print((inv(invv))) if i + 1 < X and (i + 1, j, k) not in pushed: heappush(h, (inv(A[i + 1] + B[j] + C[k]), i + 1, j, k)) pushed.append((i + 1, j, k)) if j + 1 < Y and (i, j + 1, k) not in pushed: heappush(h, (inv(A[i] + B[j + 1] + C[k]), i, j + 1, k)) pushed.append((i, j + 1, k)) if k + 1 < Z and (i, j, k + 1) not in pushed: heappush(h, (inv(A[i] + B[j] + C[k + 1]), i, j, k + 1)) pushed.append((i, j, k + 1))
p03078
from heapq import heappush, heappop X, Y, Z, K = list(map(int, input().split())) A = [int(s) for s in input().split()] B = [int(s) for s in input().split()] C = [int(s) for s in input().split()] A.sort(reverse=True) B.sort(reverse=True) C.sort(reverse=True) h = [] maxv = A[0] + B[0] + C[0] def inv(v): return maxv - v pushed = [] heappush(h, (0, 0, 0, 0)) for _ in range(K): invv, i, j, k = heappop(h) print((inv(invv))) if i + 1 < X and (i + 1, j, k) not in pushed: heappush(h, (inv(A[i + 1] + B[j] + C[k]), i + 1, j, k)) pushed.append((i + 1, j, k)) if j + 1 < Y and (i, j + 1, k) not in pushed: heappush(h, (inv(A[i] + B[j + 1] + C[k]), i, j + 1, k)) pushed.append((i, j + 1, k)) if k + 1 < Z and (i, j, k + 1) not in pushed: heappush(h, (inv(A[i] + B[j] + C[k + 1]), i, j, k + 1)) pushed.append((i, j, k + 1))
from heapq import heappush, heappop X, Y, Z, K = list(map(int, input().split())) A = [int(s) for s in input().split()] B = [int(s) for s in input().split()] C = [int(s) for s in input().split()] A.sort(reverse=True) B.sort(reverse=True) C.sort(reverse=True) h = [] maxv = A[0] + B[0] + C[0] def inv(v): return maxv - v pushed = [[[] for _ in range(Y)] for _ in range(X)] heappush(h, (0, 0, 0, 0)) for _ in range(K): invv, i, j, k = heappop(h) print((inv(invv))) if i + 1 < X and k not in pushed[i + 1][j]: heappush(h, (inv(A[i + 1] + B[j] + C[k]), i + 1, j, k)) pushed[i + 1][j].append(k) if j + 1 < Y and k not in pushed[i][j + 1]: heappush(h, (inv(A[i] + B[j + 1] + C[k]), i, j + 1, k)) pushed[i][j + 1].append(k) if k + 1 < Z and k + 1 not in pushed[i][j]: heappush(h, (inv(A[i] + B[j] + C[k + 1]), i, j, k + 1)) pushed[i][j].append(k + 1)
p03078
import heapq class PriorityQueue: def __init__(self): self.__heap = [] self.__count = 0 def empty(self) -> bool: return self.__count == 0 def dequeue(self): if self.empty(): raise Exception('empty') self.__count -= 1 return heapq.heappop(self.__heap) def enqueue(self, v): self.__count += 1 heapq.heappush(self.__heap, v) def __len__(self): return self.__count def cake123(X: int, Y: int, Z: int, K: int, A: list, B: list, C: list)->list: ret = [0] * K sA = sorted(-a for a in A) sB = sorted(-b for b in B) sC = sorted(-c for c in C) q = PriorityQueue() q.enqueue((sA[0] + sB[0] + sC[0], 0, 0, 0)) used = {} k = 0 while k < K: delicious, ai, bi, ci = q.dequeue() if -delicious in used and (ai, bi, ci) in used[-delicious]: continue used.setdefault(-delicious, set()) used[-delicious].add((ai, bi, ci)) ret[k] = -delicious k += 1 if ai+1 < X: q.enqueue((sA[ai+1] + sB[bi] + sC[ci], ai+1, bi, ci)) if bi+1 < Y: q.enqueue((sA[ai] + sB[bi+1] + sC[ci], ai, bi+1, ci)) if ci+1 < Z: q.enqueue((sA[ai] + sB[bi] + sC[ci+1], ai, bi, ci+1)) if ai+1 < X and bi+1 < Y: q.enqueue((sA[ai+1] + sB[bi+1] + sC[ci], ai+1, bi+1, ci)) if ai+1 < X and ci+1 < Z: q.enqueue((sA[ai+1] + sB[bi] + sC[ci+1], ai+1, bi, ci+1)) if bi+1 < Y and ci+1 < Z: q.enqueue((sA[ai] + sB[bi+1] + sC[ci+1], ai, bi+1, ci+1)) if ai+1 < X and bi+1 < Y and ci+1 < Z: q.enqueue((sA[ai+1] + sB[bi+1] + sC[ci+1], ai+1, bi+1, ci+1)) return ret if __name__ == "__main__": X, Y, Z, K = list(map(int, input().split())) A = [int(s) for s in input().split()] B = [int(s) for s in input().split()] C = [int(s) for s in input().split()] ans = cake123(X, Y, Z, K, A, B, C) for a in ans: print(a)
import heapq class PriorityQueue: def __init__(self): self.__heap = [] self.__count = 0 def empty(self) -> bool: return self.__count == 0 def dequeue(self): if self.empty(): raise Exception('empty') self.__count -= 1 return heapq.heappop(self.__heap) def enqueue(self, v): self.__count += 1 heapq.heappush(self.__heap, v) def __len__(self): return self.__count def cake123(X: int, Y: int, Z: int, K: int, A: list, B: list, C: list)->list: ret = [0] * K sA = sorted(-a for a in A) sB = sorted(-b for b in B) sC = sorted(-c for c in C) q = PriorityQueue() q.enqueue((sA[0] + sB[0] + sC[0], 0, 0, 0)) used = {} k = 0 while k < K: delicious, ai, bi, ci = q.dequeue() if -delicious in used and (ai, bi, ci) in used[-delicious]: continue used.setdefault(-delicious, set()) used[-delicious].add((ai, bi, ci)) ret[k] = -delicious k += 1 if ai+1 < X: q.enqueue((sA[ai+1] + sB[bi] + sC[ci], ai+1, bi, ci)) if bi+1 < Y: q.enqueue((sA[ai] + sB[bi+1] + sC[ci], ai, bi+1, ci)) if ci+1 < Z: q.enqueue((sA[ai] + sB[bi] + sC[ci+1], ai, bi, ci+1)) return ret if __name__ == "__main__": X, Y, Z, K = list(map(int, input().split())) A = [int(s) for s in input().split()] B = [int(s) for s in input().split()] C = [int(s) for s in input().split()] ans = cake123(X, Y, Z, K, A, B, C) for a in ans: print(a)
p03078
ri = lambda: int(input()) rl = lambda: list(map(int,input().split())) rr = lambda N: [ri() for _ in range(N)] YN = lambda b: print('YES') if b else print('NO') yn = lambda b: print('Yes') if b else print('No') OE = lambda x: print('Odd') if x%2 else print('Even') INF = 10**18 x,y,z,K=rl() A=rl() B=rl() C=rl() A.sort(reverse=True) B.sort(reverse=True) C.sort(reverse=True) X=[] for a,b,c in zip(A,B,C): X.append([a,0]) X.append([b,1]) X.append([c,2]) X.sort(reverse=True) ca=0 cb=0 cc=0 xl = len(X) if x*y*z>=3000: for i in range(len(X)): _,a = X[i] if a == 0: ca += 1 elif a == 1: cb += 1 else: cc += 1 if ca*cb*cc>=3000: xl=i break else: ca=x cb=y cc=z ans = [] import itertools for a,b,c in itertools.product(A[:ca],B,C): ans.append(a+b+c) if ca < x: for a,b,c in itertools.product(A[ca:],B[:cb],C): ans.append(a+b+c) if cb < y: for a,b,c in itertools.product(A[ca:],B[cb:],C[:cc]): ans.append(a+b+c) ans.sort(reverse=True) for i in range(K): print(ans[i])
ri = lambda: int(input()) rl = lambda: list(map(int,input().split())) rr = lambda N: [ri() for _ in range(N)] YN = lambda b: print('YES') if b else print('NO') yn = lambda b: print('Yes') if b else print('No') OE = lambda x: print('Odd') if x%2 else print('Even') INF = 10**18 X,Y,Z,K=rl() A=rl() B=rl() C=rl() A.sort(reverse=True) B.sort(reverse=True) C.sort(reverse=True) ans = [] for a in range(1,X+1): for b in range(1,Y+1): for c in range(1,Z+1): if a*b*c<=K: ans.append(A[a-1]+B[b-1]+C[c-1]) else: break ans.sort(reverse=True) for i in range(K): print(ans[i])
p03078
import sys #import numpy as np s2nn = lambda s: [int(c) for c in s.split(' ')] ss2nn = lambda ss: [int(s) for s in ss] ss2nnn = lambda ss: [s2nn(s) for s in ss] i2s = lambda: sys.stdin.readline().rstrip() i2n = lambda: int(i2s()) i2nn = lambda: s2nn(i2s()) ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)] ii2nn = lambda n: ss2nn(ii2ss(n)) ii2nnn = lambda n: ss2nnn(ii2ss(n)) N = 10000 def tokey(i, j, k): return i*N*N + j*N + k def dekey(n): i = int(n / N / N) j = int(n / N) % N k = n % N return i, j, k def main(): X, Y, Z, K = i2nn() A = i2nn() B = i2nn() C = i2nn() A.sort() A.reverse() B.sort() B.reverse() C.sort() C.reverse() Q = [(A[0] + B[0] + C[0], 0, 0, 0)] loop = 0 stored = set() def next(i, j, k): if i >= X or j >= Y or k >= Z: return key = tokey(i, j, k) if key not in stored: stored.add(key) n = A[i] + B[j] + C[k] Q.append((n, i, j, k)) while True: Q.sort(key=lambda v: v[0]) v = Q.pop() print((v[0])) loop += 1 if loop >= K: break next(v[1]+1, v[2], v[3]) next(v[1], v[2]+1, v[3]) next(v[1], v[2], v[3]+1) main()
import sys #import numpy as np s2nn = lambda s: [int(c) for c in s.split(' ')] ss2nn = lambda ss: [int(s) for s in ss] ss2nnn = lambda ss: [s2nn(s) for s in ss] i2s = lambda: sys.stdin.readline().rstrip() i2n = lambda: int(i2s()) i2nn = lambda: s2nn(i2s()) ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)] ii2nn = lambda n: ss2nn(ii2ss(n)) ii2nnn = lambda n: ss2nnn(ii2ss(n)) N = 10000 def tokey(i, j, k): return i*N*N + j*N + k def dekey(n): i = int(n / N / N) j = int(n / N) % N k = n % N return i, j, k def main(): X, Y, Z, K = i2nn() A = i2nn() B = i2nn() C = i2nn() A.sort() A.reverse() B.sort() B.reverse() C.sort() C.reverse() Q = [(A[0] + B[0] + C[0], 0, 0, 0)] loop = 0 stored = set() def next(i, j, k): if i >= X or j >= Y or k >= Z: return key = tokey(i, j, k) if key not in stored: stored.add(key) n = A[i] + B[j] + C[k] Q.append((n, i, j, k)) while True: v = max(Q, key=lambda v: v[0]) Q.remove(v) print((v[0])) loop += 1 if loop >= K: break next(v[1]+1, v[2], v[3]) next(v[1], v[2]+1, v[3]) next(v[1], v[2], v[3]+1) main()
p03078
x, y, z, k = list(map(int,input().split())) A = list(map(int,input().split())) B = list(map(int,input().split())) C = list(map(int,input().split())) A.sort(reverse=1) B.sort(reverse=1) C.sort(reverse=1) D = [0] * (min(k, x) * min(k, y)) for i in range(min(k, x)): for j in range(min(k, y)): D.append(A[i] + B[j]) D.sort(reverse=1) E = [0] * (min(k, len(D)) * min(k, z)) for i in range(min(k, len(D))): for j in range(min(k, z)): E.append(D[i] + C[j]) E.sort(reverse=1) for i in range(k): print((E[i]))
x, y, z, k = list(map(int,input().split())) A = list(map(int,input().split())) B = list(map(int,input().split())) C = list(map(int,input().split())) A.sort(reverse=1) B.sort(reverse=1) C.sort(reverse=1) D = [] for i in range(min(k, x)): for j in range(min(k, y)): for l in range(min(k, z)): if i*j*l <= k: D.append(A[i] + B[j] + C[l]) else: break D.sort(reverse=1) for i in range(k): print((D[i]))
p03078
import itertools X, Y, Z, K = list(map(int, input().split())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) AB = [a + b for (a, b) in list(itertools.product(A, B))] AB = sorted(AB)[::-1] ans = [ab + c for (ab, c) in list(itertools.product(AB[:3000], C))] ans = sorted(ans)[::-1] for i in range(K): print((ans[i]))
import itertools X, Y, Z, K = list(map(int, input().split())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) AB = [a + b for (a, b) in list(itertools.product(A, B))] AB.sort(reverse=True) ans = [ab + c for (ab, c) in list(itertools.product(AB[:min(3000, X*Y*Z)], C))] ans.sort(reverse=True) for i in range(K): print((ans[i]))
p03078
from itertools import product, chain x, y, z, k = list(map(int, input().split(" "))) a = sorted(list(map(int, input().split(" ")))) b = sorted(list(map(int, input().split(" ")))) c = sorted(list(map(int, input().split(" ")))) apb_sorted = sorted([a + b for a, b in product(a, b)]) ans_list = sorted( list(chain.from_iterable([[_c + ab for ab in apb_sorted] for _c in c[:k]])) ) it = reversed(ans_list) for _ in range(k): print((next(it)))
from itertools import product, chain x, y, z, k = list(map(int, input().split(" "))) a = sorted(list(map(int, input().split(" ")))) b = sorted(list(map(int, input().split(" ")))) c = sorted(list(map(int, input().split(" ")))) apb_sorted = sorted([a + b for a, b in product(a, b)])[-k:] ans_list = sorted( list(chain.from_iterable([[_c + ab for ab in apb_sorted] for _c in c[:k]])) ) it = reversed(ans_list) for _ in range(k): print((next(it)))
p03078
from itertools import product, chain from collections import deque def solver1(a, b, c, k): apb_sorted = sorted([a + b for a, b in product(a, b)])[-k:] ans_list = sorted( list(chain.from_iterable([[_c + ab for ab in apb_sorted] for _c in c[:k]])) ) it = reversed(ans_list) for _ in range(k): print((next(it))) def solver2(a, b, c, k): d = deque() n = len(a) m = min(k, n) for p in range(m): for q in range(m): for r in range(m): if (p + 1) * (q + 1) * (r + 1) > k: continue d.append(a[-p - 1] + b[-q - 1] + c[-r - 1]) it = reversed(sorted(d)) for _ in range(k): print((next(it))) if __name__ == "__main__": x, y, z, k = list(map(int, input().split(" "))) a = sorted(list(map(int, input().split(" ")))) b = sorted(list(map(int, input().split(" ")))) c = sorted(list(map(int, input().split(" ")))) solver2(a, b, c, k)
from itertools import product, chain from collections import deque def solver1(a, b, c, k): apb_sorted = sorted([a + b for a, b in product(a, b)])[-k:] ans_list = sorted( list(chain.from_iterable([[_c + ab for ab in apb_sorted] for _c in c[:k]])) ) it = reversed(ans_list) for _ in range(k): print((next(it))) def solver2(a, b, c, k): n = len(a) m = min(k, n) pqr = deque() for p in range(m): for q in range(m): for r in range(m): if (p + 1) * (q + 1) * (r + 1) > k: break else: pqr.append(a[-p - 1] + b[-q - 1] + c[-r - 1]) it = reversed(sorted(pqr)) for _ in range(k): print((next(it))) if __name__ == "__main__": x, y, z, k = list(map(int, input().split(" "))) a = sorted(list(map(int, input().split(" ")))) b = sorted(list(map(int, input().split(" ")))) c = sorted(list(map(int, input().split(" ")))) solver2(a, b, c, k)
p03078
# -*- coding: utf-8 -*- X, Y, Z, K = list(map(int, input().split())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) E = [] for i in range(X): for j in range(Y): E.append(A[i] + B[j]) E.sort(reverse=True) F = [] for i in range(min(X * Y, K)): for j in range(Z): F.append(E[i] + C[j]) F.sort(reverse=True) for i in range(K): print((F[i]))
# -*- coding: utf-8 -*- X, Y, Z, K = list(map(int, input().split())) 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) Comb = [] for i in range(X): for j in range(Y): if (i + 1) * (j + 1) > K: break for k in range(Z): if (i + 1) * (j + 1) * (k + 1) > K: break Comb.append(A[i] + B[j] + C[k]) Comb.sort(reverse=True) for i in range(K): print((Comb[i]))
p03078
l = [int(x) for x in input().split()] x = [int(x) for x in input().split()] y = [int(x) for x in input().split()] z = [int(x) for x in input().split()] result_l = [] for i in x: for j in y: for k in z: result_l.append(i+j+k) result_l.sort(reverse=True) for ind in range(l[-1]): print((result_l[ind]))
X, Y, Z, K = map(int, input().split()) A = [int(x) for x in input().split()] A.sort(reverse=True) B = [int(x) for x in input().split()] B.sort(reverse=True) C = [int(x) for x in input().split()] C.sort(reverse=True) bi_comb = [] for i in A[:K]: for j in B[:K]: bi_comb.append(i+j) bi_comb.sort(reverse=True) tri_comb = [] for k in bi_comb[:K]: for l in C[:K]: tri_comb.append(k + l) tri_comb.sort(reverse=True) print(*tri_comb[:K], sep="\n")
p03078
X, Y, Z, K = map(int, input().split()) A = [int(x) for x in input().split()] A.sort(reverse=True) B = [int(x) for x in input().split()] B.sort(reverse=True) C = [int(x) for x in input().split()] C.sort(reverse=True) bi_comb = [] for i in A[:K]: for j in B[:K]: bi_comb.append(i+j) bi_comb.sort(reverse=True) tri_comb = [] for k in bi_comb[:K]: for l in C[:K]: tri_comb.append(k + l) tri_comb.sort(reverse=True) print(*tri_comb[:K], sep="\n")
X, Y, Z, K = map(int, input().split()) A = sorted([int(x) for x in input().split()], reverse=True) B = sorted([int(x) for x in input().split()], reverse=True) C = sorted([int(x) for x in input().split()], reverse=True) bi_comb = [] for i in range(min(X, K)): for j in range(min(Y, K)): if (i+1)*(j+1) > K: break bi_comb.append(A[i] + B[j]) bi_comb.sort(reverse=True) tri_comb = [] for k in range(min(len(bi_comb), K)): for l in range(min(Z, K)): if (k+1)*(l+1) > K: break tri_comb.append(bi_comb[k] + C[l]) tri_comb.sort(reverse=True) print(*tri_comb[:K], sep="\n")
p03078
# -*- coding: utf-8 -*- import bisect import heapq import math import random import sys from collections import Counter, defaultdict, deque from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal from functools import lru_cache, reduce from itertools import combinations, combinations_with_replacement, product, permutations from operator import add, mul, sub sys.setrecursionlimit(100000) def read_int(): return int(input()) def read_int_n(): return list(map(int, input().split())) def read_float(): return float(input()) def read_float_n(): return list(map(float, input().split())) def read_str(): return input().strip() def read_str_n(): return list(map(str, input().split())) def error_print(*args): print(*args, file=sys.stderr) def mt(f): import time def wrap(*args, **kwargs): s = time.time() ret = f(*args, **kwargs) e = time.time() error_print(e - s, 'sec') return ret return wrap @mt def slv(A, B, C, K): q = [] for a in A: for b in B: for c in C: if len(q) == K: heapq.heappushpop(q, a+b+c) else: heapq.heappush(q, a+b+c) a = [ heapq.heappop(q) for _ in range(K) ] for v in reversed(a): print(v) def main(): # N = read_int() X, Y, Z, K = read_int_n() A = read_int_n() B = read_int_n() C = read_int_n() (slv(A, B, C, K)) if __name__ == '__main__': main()
# -*- coding: utf-8 -*- import bisect import heapq import math import random import sys from collections import Counter, defaultdict, deque from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal from functools import lru_cache, reduce from itertools import combinations, combinations_with_replacement, product, permutations from operator import add, mul, sub sys.setrecursionlimit(100000) def read_int(): return int(input()) def read_int_n(): return list(map(int, input().split())) def read_float(): return float(input()) def read_float_n(): return list(map(float, input().split())) def read_str(): return input().strip() def read_str_n(): return list(map(str, input().split())) def error_print(*args): print(*args, file=sys.stderr) def mt(f): import time def wrap(*args, **kwargs): s = time.time() ret = f(*args, **kwargs) e = time.time() error_print(e - s, 'sec') return ret return wrap @mt def slv(A, B, C, K): A.sort(reverse=True) B.sort(reverse=True) C.sort(reverse=True) def s(i, j, k): return A[i] + B[j] + C[k] used = set() cand = [] if 1 < len(A): heapq.heappush(cand, (-s(1, 0, 0), (1, 0, 0))) used.add((1, 0, 0)) if 1 < len(B): heapq.heappush(cand, (-s(0, 1, 0), (0, 1, 0))) used.add((0, 1, 0)) if 1 < len(C): heapq.heappush(cand, (-s(0, 0, 1), (0, 0, 1))) used.add((0, 0, 1)) print(s(0, 0, 0)) for _ in range(K-1): v, i = heapq.heappop(cand) print(-v) ti = (i[0]+1, i[1], i[2]) if ti[0] < len(A) and ti not in used: heapq.heappush(cand, (-s(*ti), ti)) used.add(ti) ti = (i[0], i[1]+1, i[2]) if ti[1] < len(B) and ti not in used: heapq.heappush(cand, (-s(*ti), ti)) used.add(ti) ti = (i[0], i[1], i[2]+1) if ti[2] < len(C) and ti not in used: heapq.heappush(cand, (-s(*ti), ti)) used.add(ti) def main(): # for _ in range(1000): # K = 3000 # A = [random.randint(1, 10000000000) for _ in range(random.randint(1, 1000))] # B = [random.randint(1, 10000000000) for _ in range(random.randint(1, 1000))] # C = [random.randint(1, 10000000000) for _ in range(random.randint(1, 1000))] # K = min(K, len(A) + len(B) + len(C)) # slv(A,B,C,K) # N = read_int() X, Y, Z, K = read_int_n() A = read_int_n() B = read_int_n() C = read_int_n() (slv(A, B, C, K)) if __name__ == '__main__': main()
p03078
# -*- coding: utf-8 -*- import bisect import heapq import math import random import sys from collections import Counter, defaultdict, deque from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal from functools import lru_cache, reduce from itertools import combinations, combinations_with_replacement, product, permutations from operator import add, mul, sub sys.setrecursionlimit(100000) def read_int(): return int(input()) def read_int_n(): return list(map(int, input().split())) def read_float(): return float(input()) def read_float_n(): return list(map(float, input().split())) def read_str(): return input().strip() def read_str_n(): return list(map(str, input().split())) def error_print(*args): print(*args, file=sys.stderr) def mt(f): import time def wrap(*args, **kwargs): s = time.time() ret = f(*args, **kwargs) e = time.time() error_print(e - s, 'sec') return ret return wrap @mt def slv(A, B, C, K): A.sort(reverse=True) B.sort(reverse=True) C.sort(reverse=True) def s(i, j, k): return A[i] + B[j] + C[k] used = set() cand = [] if 1 < len(A): heapq.heappush(cand, (-s(1, 0, 0), (1, 0, 0))) used.add((1, 0, 0)) if 1 < len(B): heapq.heappush(cand, (-s(0, 1, 0), (0, 1, 0))) used.add((0, 1, 0)) if 1 < len(C): heapq.heappush(cand, (-s(0, 0, 1), (0, 0, 1))) used.add((0, 0, 1)) print(s(0, 0, 0)) for _ in range(K-1): v, i = heapq.heappop(cand) print(-v) ti = (i[0]+1, i[1], i[2]) if ti[0] < len(A) and ti not in used: heapq.heappush(cand, (-s(*ti), ti)) used.add(ti) ti = (i[0], i[1]+1, i[2]) if ti[1] < len(B) and ti not in used: heapq.heappush(cand, (-s(*ti), ti)) used.add(ti) ti = (i[0], i[1], i[2]+1) if ti[2] < len(C) and ti not in used: heapq.heappush(cand, (-s(*ti), ti)) used.add(ti) def main(): # for _ in range(1000): # K = 3000 # A = [random.randint(1, 10000000000) for _ in range(random.randint(1, 1000))] # B = [random.randint(1, 10000000000) for _ in range(random.randint(1, 1000))] # C = [random.randint(1, 10000000000) for _ in range(random.randint(1, 1000))] # K = min(K, len(A) + len(B) + len(C)) # slv(A,B,C,K) # N = read_int() X, Y, Z, K = read_int_n() A = read_int_n() B = read_int_n() C = read_int_n() (slv(A, B, C, K)) if __name__ == '__main__': main()
# -*- coding: utf-8 -*- import bisect import heapq import math import random import sys from collections import Counter, defaultdict, deque from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal from functools import lru_cache, reduce from itertools import combinations, combinations_with_replacement, product, permutations from operator import add, mul, sub sys.setrecursionlimit(100000) def read_int(): return int(input()) def read_int_n(): return list(map(int, input().split())) def read_float(): return float(input()) def read_float_n(): return list(map(float, input().split())) def read_str(): return input().strip() def read_str_n(): return list(map(str, input().split())) def error_print(*args): print(*args, file=sys.stderr) def mt(f): import time def wrap(*args, **kwargs): s = time.time() ret = f(*args, **kwargs) e = time.time() error_print(e - s, 'sec') return ret return wrap @mt def slv(A, B, C, K): A.sort(reverse=True) B.sort(reverse=True) C.sort(reverse=True) def s(i, j, k): return A[i] + B[j] + C[k] used = set() cand = [] heapq.heappush(cand, (-s(0, 0, 0), (0, 0, 0))) for _ in range(K): v, i = heapq.heappop(cand) print(-v) ti = (i[0]+1, i[1], i[2]) if ti[0] < len(A) and ti not in used: heapq.heappush(cand, (-s(*ti), ti)) used.add(ti) ti = (i[0], i[1]+1, i[2]) if ti[1] < len(B) and ti not in used: heapq.heappush(cand, (-s(*ti), ti)) used.add(ti) ti = (i[0], i[1], i[2]+1) if ti[2] < len(C) and ti not in used: heapq.heappush(cand, (-s(*ti), ti)) used.add(ti) def main(): # for _ in range(1000): # K = 3000 # A = [random.randint(1, 10000000000) for _ in range(random.randint(1, 1000))] # B = [random.randint(1, 10000000000) for _ in range(random.randint(1, 1000))] # C = [random.randint(1, 10000000000) for _ in range(random.randint(1, 1000))] # K = min(K, len(A) + len(B) + len(C)) # slv(A,B,C,K) # N = read_int() X, Y, Z, K = read_int_n() A = read_int_n() B = read_int_n() C = read_int_n() (slv(A, B, C, K)) if __name__ == '__main__': main()
p03078
x, y, z, k = list(map(int, input().split())) m = [] for _ in range(3): m.append(sorted(list(map(int, input().split())), reverse=True)) def sorted_sum(list_a, list_b): s = [] for x in list_a: for y in list_b: s.append(x + y) return sorted(s, reverse=True) ans = sorted_sum(sorted_sum(m[0], m[1])[0:k], m[2]) for i in range(0, k): print((ans[i]))
x, y, z, k = list(map(int, input().split())) m = [] for _ in range(3): m.append(sorted(list(map(int, input().split())), reverse=True)) def sorted_sum(list_a, list_b, limit): s = [] for x in list_a: for y in list_b: s.append(x + y) return sorted(s, reverse=True)[0:limit] def consume_diff(s, a_val, list_b, b_index): diff = a_val - list_b[b_index] for i in range(b_index + 1, len(list_b)): if list_b[b_index] - list_b[i] > diff: break s.append(a_val + list_b[i]) ans = sorted_sum(sorted_sum(m[0], m[1], k), m[2], k) for i in range(min([k, len(ans)])): print((ans[i]))
p03078
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] * z for _ in range(y)] for _ in range(x)] cnt = 0 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][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
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]))
p03078
X,Y,Z,K = list(map(int,input().split())) A = list(map(int,input().split())) B = list(map(int,input().split())) C = list(map(int,input().split())) S = [] for x in A: for y in B: for z in C: S.append(x+y+z) S.sort(reverse = True) for i in range(K): print((S[i]))
X,Y,Z,K = list(map(int,input().split())) A = list(map(int,input().split())) B = list(map(int,input().split())) C = list(map(int,input().split())) S = [] for x in A: for y in B: S.append(x+y) S.sort(reverse = True) S1 = [] for i in range(min(K,X*Y)): for z in C: S1.append(S[i]+z) S1.sort(reverse = True) for i in range(K): print((S1[i]))
p03078
x,y,z,k = list(map(int,input().split())) a = list(map(int,input().split())) b = list(map(int,input().split())) c = list(map(int,input().split())) ans = [] for i in range(x): for j in range(y): for l in range(z): ans.append(a[i] + b[j] + c[l]) ans.sort(reverse=True) for i in range(k): print((ans[i]))
x,y,z,k = list(map(int,input().split())) a = list(map(int,input().split())) b = list(map(int,input().split())) c = list(map(int,input().split())) ans = [] for i in range(x): for j in range(y): ans.append(a[i]+b[j]) ans.sort(reverse=True) ans = ans[:k] ans2 = [] for i in range(len(ans)): for j in range(z): ans2.append(ans[i]+c[j]) ans2.sort(reverse=True) for i in range(k): print((ans2[i]))
p03078
x, y, z, k = list(map(int, input().split())) a = list(map(int, input().split())) b = list(map(int, input().split())) c = list(map(int, input().split())) c.sort(reverse=True) p = [0 for _ in range(x * y)] t = 0 for ai in a: for bi in b: p[t] = ai + bi t += 1 p.sort(reverse=True) q = [0 for _ in range(k * z)] t = 0 for pi in p[:k]: for ci in c[:k]: q[t] = pi + ci t += 1 q.sort(reverse=True) for qi in q[:k]: print(qi)
x, y, z, kk = list(map(int, input().split())) a = list(map(int, input().split())) b = list(map(int, input().split())) c = list(map(int, input().split())) a.sort(reverse=True) b.sort(reverse=True) c.sort(reverse=True) p = [] for i in range(x): for j in range(y): for k in range(z): if (i + 1) * (j + 1) * (k + 1) <= kk: p.append(a[i] + b[j] + c[k]) else: break p.sort(reverse=True) for i in range(kk): print((p[i]))
p03078
X, Y, Z, K = list(map(int, input().split())) 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) s = [] for i in A: for j in B: for k in C: s.append(i+j+k) s = sorted(s, reverse=True) for i in range(K): print((s[i]))
X, Y, Z, K = list(map(int, input().split())) 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) e = [] s = [] for i in A: for j in B: e.append(i+j) e = sorted(e, reverse=True) if K<len(e): e = e[0:K] for i in e: for j in C: s.append(i+j) s = sorted(s, reverse=True) for i in range(K): print((s[i]))
p03078
x,y,z,k=list(map(int,input().split())) a=tuple(map(int,input().split())) b=tuple(map(int,input().split())) c=tuple(map(int,input().split())) def f(p,q): return [i+j for j in q for i in p] if x+y<y+z: for i in sorted(f(c,f(a,b)))[::-1][:k]: print(i) elif x+z<y+z: for i in sorted(f(b,f(a,c)))[::-1][:k]: print(i) else: for i in sorted(f(a,f(b,c)))[::-1][:k]: print(i)
x,y,z,k=list(map(int,input().split())) a=tuple(map(int,input().split())) b=tuple(map(int,input().split())) c=tuple(map(int,input().split())) def f(p,q): return sorted([i+j for j in q for i in p])[::-1][:k] if x+y<y+z: for i in sorted(f(c,f(a,b)))[::-1][:k]: print(i) elif x+z<y+z: for i in sorted(f(b,f(a,c)))[::-1][:k]: print(i) else: for i in sorted(f(a,f(b,c)))[::-1][:k]: print(i)
p03078
X, Y, Z, K = list(map(int, input().split())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) ab=sorted(s+t for t in B for s in A)[-1:-K-1:-1] abc=sorted(i+x for i in ab for x in C)[-1:-K-1:-1] print(("\n".join(map(str,abc))))
X, Y, Z, K = list(map(int, input().split())) A = sorted(map(int, input().split())) B = sorted(map(int, input().split())) C = sorted(map(int, input().split())) ab=sorted(s+t for t in B for s in A)[-1:-K-1:-1] abc=sorted(i+x for i in ab for x in C)[-1:-K-1:-1] print(("\n".join(map(str,abc))))
p03078
X, Y, Z, K = list(map(int, input().split())) A = sorted(map(int, input().split())) B = sorted(map(int, input().split())) C = sorted(map(int, input().split())) ab=sorted(s+t for t in B for s in A)[-1:-K-1:-1] abc=sorted(i+x for i in ab for x in C)[-1:-K-1:-1] print(("\n".join(map(str,abc))))
X, Y, Z, K = map(int, input().split()) A = sorted(map(int, input().split())) B = sorted(map(int, input().split())) C = sorted(map(int, input().split())) ab=sorted(s+t for t in B for s in A)[-1:-K-1:-1] abc=sorted(i+x for i in ab for x in C)[-1:-K-1:-1] print(*abc,sep="\n")
p03078
def binary_search_int(ok, ng, test, k, A, B): """ :param ok: solve(x) = True を必ず満たす点 :param ng: solve(x) = False を必ず満たす点 """ while abs(ok - ng) > 1: mid = (ok + ng) // 2 if test(mid, k, A, B): ok = mid else: ng = mid return ok def get_cnt(x, A, B): """ a+b<=x となるようなAの要素とBの要素の組の数 (A, Bはソート済み) """ cnt = 0 L = len(B) for a in A: cnt += L-bisect_left(B, x-a) return cnt def test(x, k, A, B): """ 場合の数が k 個(以上)となるような最小の x を探索する関数 a+b <= x で get_cnt(x,A,B) は同じ値を返すので、最小の x は A, Bの要素の和そのものに一致する """ return get_cnt(x,A,B) >= k ########################################################### import sys input = sys.stdin.readline from bisect import * 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.sort() B.sort() C.sort() P = [] for k in range(1,K+1): tmp = binary_search_int(0, 10**11,test, k, A, B) if tmp != 0: P.append(tmp) Q = [] P.sort() for k in range(1,K+1): Q.append(binary_search_int(1, 10**11,test, k, P, C)) print(*Q, sep="\n")
from itertools import product X, Y, Z, K = list(map(int, input().split())) AB = [] for ab in product(list(map(int, input().split())), list(map(int, input().split()))): AB.append(ab[0] + ab[1]) AB.sort(reverse=True) AB = AB[:K] ABC = [] for abc in product(AB, list(map(int, input().split()))): ABC.append(abc[0]+abc[1]) ABC.sort(reverse=True) for i in range(K): print((ABC[i]))
p03078
from itertools import product X, Y, Z, K = list(map(int, input().split())) AB = [] for ab in product(list(map(int, input().split())), list(map(int, input().split()))): AB.append(ab[0] + ab[1]) AB.sort(reverse=True) AB = AB[:K] ABC = [] for abc in product(AB, list(map(int, input().split()))): ABC.append(abc[0]+abc[1]) ABC.sort(reverse=True) for i in range(K): print((ABC[i]))
from itertools import product X, Y, Z, K = list(map(int, input().split())) AB = [] for ab in product(list(map(int, input().split())), list(map(int, input().split()))): AB.append(ab[0] + ab[1]) AB.sort(reverse=True) AB = AB[:min(K,X*Y)] ABC = [] for abc in product(AB, list(map(int, input().split()))): ABC.append(abc[0]+abc[1]) ABC.sort(reverse=True) for i in range(K): print((ABC[i]))
p03078
#!/usr/bin/env python3 (x, y, z, k), a, b, c = [[*list(map(int, o.split()))] for o in open(0)] a.sort(); b.sort(); c.sort() p = a[-1] + b[-1] + c[-1] s, h = {(p, -1, -1, -1)}, [(-p, -1, -1, -1)] from heapq import* def push(i, j, k): global s, h try: t = a[i] + b[j] + c[k] except IndexError: return if (t, i, j, k) not in s: heappush(h, (-t, i, j, k)) s |= {(t, i, j, k)} for _ in [0] * k: p, i, j, k = heappop(h) print((-p)) push(i, j, k - 1) push(i, j - 1, k) push(i - 1, j, k)
#!/usr/bin/env python3 (x, y, z, k), a, b, c = [[*list(map(int, o.split()))] for o in open(0)] a.sort(); b.sort(); c.sort() h = [(-(a[-1] + b[-1] + c[-1]), -1, -1, -1)] s = set(h) from heapq import* def push(i, j, k): global s, h try: t = (- (a[i] + b[j] + c[k]), i, j, k) except IndexError: return if t not in s: heappush(h, t) s |= {t} for _ in [0] * k: p, i, j, k = heappop(h) print((-p)) push(i, j, k - 1) push(i, j - 1, k) push(i - 1, j, k)
p03078
from queue import PriorityQueue X,Y,Z,K = list(map(int, input().split())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) A.sort(reverse=True) A.append(-float('inf')) B.sort(reverse=True) B.append(-float('inf')) C.sort(reverse=True) C.append(-float('inf')) pq = PriorityQueue() pq.put((-(A[0]+B[0]+C[0]),0,0,0)) count = 0 queued = set([(0,0,0)]) while True: d,i,j,k = pq.get() #print(-d,i,j,k) print((-d)) count += 1 if count >= K: break for l in [i,i+1]: for m in [j,j+1]: for n in [k,k+1]: if (l,m,n) in queued: continue else: pq.put((-(A[l]+B[m]+C[n]),l,m,n)) queued.add((l,m,n))
from heapq import heappop, heappush from time import time X,Y,Z,K = list(map(int, input().split())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) A.sort(reverse=True) A.append(-float('inf')) B.sort(reverse=True) B.append(-float('inf')) C.sort(reverse=True) C.append(-float('inf')) hq = [] count = 0 queued = set() heappush(hq,(-(A[0]+B[0]+C[0]),time(),0,0,0)) queued.add((0,0,0)) while True: d,_,i,j,k = heappop(hq) #print(-d,i,j,k) print((-d)) count += 1 if count >= K: break for l in [i,i+1]: for m in [j,j+1]: for n in [k,k+1]: if (l,m,n) in queued: continue else: heappush(hq,(-(A[l]+B[m]+C[n]),time(),l,m,n)) queued.add((l,m,n))
p03078
def main(): 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()] ans = [] for aa in a: for bb in b: for cc in c: ans.append(aa+bb+cc) ans.sort(reverse=True) for aa in ans[:k]: print(aa) if __name__ == '__main__': main()
def main(): 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()] ab = [] for aa in a: for bb in b: ab.append(aa+bb) ab.sort(reverse=True) abc = [] for i in range(min(k,len(ab))): for j in range(len(c)): abc.append(ab[i]+c[j]) abc.sort(reverse=True) for i in range(k): print((abc[i])) if __name__ == '__main__': main()
p03078
from itertools import product import sys input = sys.stdin.readline X, Y, Z, K = list(map(int, input().split())) A = [int(_) for _ in input().split()] B = [int(_) for _ in input().split()] C = [int(_) for _ in input().split()] A = sorted(A)[::-1] B = sorted(B)[::-1] C = sorted(C)[::-1] cnt = 0 Ax = 0 Bx = 0 Cx = 0 while cnt <= K: if Ax < X-1: a = A[Ax]-A[Ax+1] else: a = float('inf') if Bx < Y-1: b = B[Bx]-B[Bx+1] else: b = float('inf') if Cx < Z-1: c = C[Cx]-C[Cx+1] else: c = float('inf') if a <= b and a <= c: Ax += 1 elif b <= a and b <= c: Bx += 1 else: Cx += 1 cnt += 1 List = [] for i, j, k in product(A[:Ax+1], B[:Bx+1], C[:Cx+1]): List.append(i+j+k) List = sorted(List)[::-1] for i in range(K): print((List[i]))
X, Y, Z, K = list(map(int, input().split())) A = [int(_) for _ in input().split()] B = [int(_) for _ in input().split()] C = [int(_) for _ in input().split()] A = sorted(A)[::-1] B = sorted(B)[::-1] C = sorted(C)[::-1] List = [] for i in range(X): for j in range(Y): for k in range(Z): if (i+1)*(j+1)*(k+1) > K: break else: List.append(A[i]+B[j]+C[k]) List = sorted(List)[-1:-K-1:-1] for i in range(K): print((List[i]))
p03078
X, Y, Z, K = list(map(int, input().split())) 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) ans = [] for x in range(X): if x >= K: break for y in range(Y): if x + y >= K: break for z in range(Z): if x + y + z >= K: break value = A[x] + B[y] + C[z] ans.append(value) ans.sort(reverse=True) for i in range(K): print((ans[i]))
X, Y, Z, K = list(map(int, input().split())) 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) ans = [] for x in range(X): if x+1 > K: break for y in range(Y): if (x+1) * (y+1) > K: break for z in range(Z): if (x+1) * (y+1) * (z+1) > K: break value = A[x] + B[y] + C[z] ans.append(value) ans.sort(reverse=True) for i in range(K): print((ans[i]))
p03078
import sys if __name__ == "__main__": (X, Y, Z, K) = list(map(int, sys.stdin.readline().split())) A = list(map(int, sys.stdin.readline().split())) B = list(map(int, sys.stdin.readline().split())) C = list(map(int, sys.stdin.readline().split())) v = [] for a in A: for b in B: v.append(a + b) v.sort(reverse=True) ans = [] for i in range(min(len(v),3000)): for c in C: ans.append(v[i] + c) ans.sort(reverse=True) for i in range(K): sys.stdout.write("%d\n" % ans[i])
import sys if __name__ == "__main__": (X, Y, Z, K) = list(map(int, sys.stdin.readline().split())) A = list(map(int, sys.stdin.readline().split())) B = list(map(int, sys.stdin.readline().split())) C = list(map(int, sys.stdin.readline().split())) A.sort(reverse=True) B.sort(reverse=True) C.sort(reverse=True) v = [] for a in range(len(A)): for b in range(len(B)): if (a + 1) * (b + 1) > K: break for c in range(len(C)): if (a + 1) * (b + 1) * (c + 1) > K: break v.append(A[a] + B[b] + C[c]) v.sort(reverse=True) for i in range(K): sys.stdout.write("%d\n" % v[i])
p03078
X,Y,Z,K=list(map(int,input().split())) A= list(map(int,input().split())) B= list(map(int,input().split())) C= list(map(int,input().split())) AB=[0]*(X*Y) t=0 for i in A: for j in B: AB[t]=i+j t+=1 AB.sort(reverse=True) ABA=AB[0:min(K,X*Y)] D=[0]*(Z*len(ABA)) t=0 for i in ABA: for j in C: D[t]=i+j t+=1 D.sort(reverse=True) for i in range(K): print((D[i]))
X,Y,Z,K=list(map(int,input().split())) A= list(map(int,input().split())) B= list(map(int,input().split())) C= list(map(int,input().split())) A.sort(reverse=True) B.sort(reverse=True) C.sort(reverse=True) ans=[] for i in range(min(X,K)): D=int(K/(i+1))+1 for j in range(min(D,Y,K)): E=int(D/(j+1))+1 for k in range(min(E,Z,K)): ans.append(A[i]+B[j]+C[k]) ans.sort(reverse=True) for i in range(K): print((ans[i]))
p03078
import heapq # heapqライブラリのimport X,Y,Z,K=list(map(int,input().split())) A= list(map(int,input().split())) B= list(map(int,input().split())) C= list(map(int,input().split())) A.sort(reverse=True) B.sort(reverse=True) C.sort(reverse=True) check=[[0,0,0]] lst =[(-(A[0]+B[0]+C[0]),0,0,0)] heapq.heapify(lst) for r in range(K): a=lst[0][1] b=lst[0][2] c=lst[0][3] print((lst[0][0]*(-1))) heapq.heappop(lst) if a<X-1 : if [a+1,b,c] not in check: heapq.heappush(lst, (-(A[a+1]+B[b]+C[c]),a+1,b,c)) check.append([a+1,b,c]) if b<Y-1 : if [a,b+1,c] not in check: heapq.heappush(lst, (-(A[a]+B[b+1]+C[c]),a,b+1,c)) check.append([a,b+1,c]) if c<Z-1 : if [a,b,c+1] not in check: heapq.heappush(lst, (-(A[a]+B[b]+C[c+1]),a,b,c+1)) check.append([a,b,c+1])
import heapq # heapqライブラリのimport X,Y,Z,K=list(map(int,input().split())) A= list(map(int,input().split())) B= list(map(int,input().split())) C= list(map(int,input().split())) A.sort(reverse=True) B.sort(reverse=True) C.sort(reverse=True) dic={} dic[(0,0,0)]=1 lst =[(-(A[0]+B[0]+C[0]),0,0,0)] heapq.heapify(lst) for r in range(K): a=lst[0][1] b=lst[0][2] c=lst[0][3] print((lst[0][0]*(-1))) heapq.heappop(lst) if a<X-1 : if (a+1,b,c) not in dic: heapq.heappush(lst, (-(A[a+1]+B[b]+C[c]),a+1,b,c)) dic[(a+1,b,c)]=1 if b<Y-1 : if (a,b+1,c) not in dic: heapq.heappush(lst, (-(A[a]+B[b+1]+C[c]),a,b+1,c)) dic[(a,b+1,c)]=1 if c<Z-1 : if (a,b,c+1) not in dic: heapq.heappush(lst, (-(A[a]+B[b]+C[c+1]),a,b,c+1)) dic[(a,b,c+1)]=1
p03078
X,Y,Z,K = list(map(int,input().split())) 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) ma,mb,mc = A[0],B[0],C[0] sA = [a-ma for a in A] + [-10**15] sB = [b-mb for b in B] + [-10**15] sC = [c-mc for c in C] + [-10**15] ia,ib,ic = 0,0,0 while min(10**7,(X)*(Y)*(Z)) > (ia+1)*(ib+1)*(ic+1): m = max(sA[ia+1],sB[ib+1],sC[ic+1]) if ia < (X-1) and sA[ia+1] == m: ia = min(ia+1,X-1) if ib < (Y-1) and sB[ib+1] == m: ib = min(ib+1,Y-1) if ic < (Z-1) and sC[ic+1] == m: ic = min(ic+1,Z-1) ans = [] for a in A[:ia+1]: for b in B[:ib+1]: for c in C[:ic+1]: ans.append(a+b+c) ans.sort(reverse=True) for out in ans[:K]: print(out)
X,Y,Z,K = list(map(int,input().split())) 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) ma,mb,mc = A[0],B[0],C[0] sA = [a-ma for a in A] + [-10**15] sB = [b-mb for b in B] + [-10**15] sC = [c-mc for c in C] + [-10**15] ia,ib,ic = 0,0,0 while min(10**5,(X)*(Y)*(Z)) > (ia+1)*(ib+1)*(ic+1): m = max(sA[ia+1],sB[ib+1],sC[ic+1]) if ia < (X-1) and sA[ia+1] == m: ia = min(ia+1,X-1) if ib < (Y-1) and sB[ib+1] == m: ib = min(ib+1,Y-1) if ic < (Z-1) and sC[ic+1] == m: ic = min(ic+1,Z-1) ans = [] for a in A[:ia+1]: for b in B[:ib+1]: for c in C[:ic+1]: ans.append(a+b+c) ans.sort(reverse=True) for out in ans[:K]: print(out)
p03078
from heapq import heappop , heappush X , Y , Z , K = list(map(int,input().split())) A = list(map(int,input().split())) B = list(map(int,input().split())) C = list(map(int,input().split())) # それぞれソート A.sort(reverse=True) B.sort(reverse=True) C.sort(reverse=True) # 処理済みフラグ confilm = [] q = [(-(A[0] + B[0] + C[0]) , 0,0,0)] for _ in range(K) : val , i , j , k = heappop(q) print((-val)) t = (i+1,j,k) if i + 1 < X and not t in confilm : heappush(q,(-(A[i+1] + B[j] + C[k]),) + t) confilm.append(t) t = (i,j+1,k) if j + 1 < Y and not t in confilm : heappush(q,(-(A[i] + B[j+1] + C[k]),) + t) confilm.append(t) t = (i,j,k+1) if k + 1 < Z and not t in confilm : heappush(q,(-(A[i] + B[j] + C[k+1]),) + t) confilm.append(t)
from heapq import heappush, heappop 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.sort(reverse=True) B.sort(reverse=True) C.sort(reverse=True) V = set() que = [(-(A[0] + B[0] + C[0]), 0, 0, 0)] V.add((0, 0, 0)) ans = [] for _ in range(K): val, a, b, c = heappop(que) ans.append(-val) for x, y, z in [(0, 0, 1), (0, 1, 0), (1, 0, 0)]: x = min(a + x, X - 1) y = min(b + y, Y - 1) z = min(c + z, Z - 1) if not (x, y, z) in V: heappush(que, (-(A[x] + B[y] + C[z]), x, y, z)) V.add((x, y, z)) print(*ans, sep='\n')
p03078
import itertools X, Y, Z, K = list(map(int, input().split())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) AB = [a + b for (a, b) in list(itertools.product(A, B))] AB.sort(reverse=True) ans = [ab + c for (ab, c) in list(itertools.product(AB[:min(3000, X*Y*Z)], C))] ans.sort(reverse=True) for i in range(K): print((ans[i]))
from itertools import product 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()] BC = [i+j for i,j in list(product(B,C))] BC.sort(reverse=True) ans = [i+j for i,j in list(product(BC[:min(3000, X*Y*Z)], A))] ans.sort(reverse=True) [print(ans[i]) for i in range(K)]
p03078
x, y, z, k = list(map(int, input().split())) a = list(int(i) for i in input().split()) b = list(int(i) for i in input().split()) c = list(int(i) for i in input().split()) sums = [] for i in range(x): for j in range(y): for l in range(z): sums.append(a[i] + b[j] + c[l]) sums.sort() ans = sums[::-1] for i in range(k): print((ans[i]))
x, y, z, k = list(map(int, input().split())) A = list(int(i) for i in input().split()) B = list(int(i) for i in input().split()) C = list(int(i) for i in input().split()) A.sort() A = A[::-1] B.sort() B = B[::-1] C.sort() C = C[::-1] ABC = [] for a in range(len(A)): for b in range(len(B)): if (a+1)*(b+1) > k: break for c in range(len(C)): if (a+1)*(b+1)*(c+1) > k: break #print(A[a], B[b], C[c]) ABC.append(A[a]+B[b]+C[c]) ABC.sort() ABC = ABC[::-1] for i in range(k): print((ABC[i]))
p03078
import heapq x, y, z, k = [ int(v) for v in input().split() ] x_list = sorted([ int(v) for v in input().split() ], reverse = True) y_list = sorted([ int(v) for v in input().split() ], reverse = True) z_list = sorted([ int(v) for v in input().split() ], reverse = True) check_list = [ [ [ False for i in range(x) ] for j in range(y) ] for l in range(z)] check_list_x, check_list_y, check_list_z = [ 0 for i in range(x) ], [ 0 for i in range(y) ], [ 0 for i in range(z) ] cake_list = [] def maling_cake(a,b,c): d = x_list[a]+y_list[b]+z_list[c] return (-d,a,b,c) for i in range(k): if i == 0: print((-maling_cake(0,0,0)[0])) check_list[0][0][0] = 1 if x > 1: heapq.heappush(cake_list, maling_cake(1,0,0)) check_list[1][0][0] = 1 if y > 1: heapq.heappush(cake_list, maling_cake(0,1,0)) check_list[0][1][0] = 1 if z > 1: heapq.heappush(cake_list, maling_cake(0,0,1)) check_list[0][0][1] = 1 else: di, ai, bi, ci = heapq.heappop(cake_list) if ai < x - 1: if check_list[ai+1][bi][ci] == 0: heapq.heappush(cake_list, maling_cake(ai+1,bi,ci)) check_list[ai+1][bi][ci] = 1 if bi < y - 1: if check_list[ai][bi+1][ci] == 0: heapq.heappush(cake_list, maling_cake(ai,bi+1,ci)) check_list[ai][bi+1][ci] = 1 if ci < z - 1: if check_list[ai][bi][ci+1] == 0: heapq.heappush(cake_list, maling_cake(ai,bi,ci+1)) check_list[ai][bi][ci+1] = 1 print((-di))
import heapq x, y, z, k = [ int(v) for v in input().split() ] x_list = sorted([ int(v) for v in input().split() ], reverse = True) y_list = sorted([ int(v) for v in input().split() ], reverse = True) z_list = sorted([ int(v) for v in input().split() ], reverse = True) cake_list = [] num_set = set([0]) def hash2(a,b,c): return 10**8*a+10**4*b+c def maling_cake(a,b,c): d = x_list[a]+y_list[b]+z_list[c] return (-d,a,b,c) for i in range(k): if i == 0: print((-maling_cake(0,0,0)[0])) if x > 1: heapq.heappush(cake_list, maling_cake(1,0,0)) num_set.add(hash2(1,0,0)) if y > 1: heapq.heappush(cake_list, maling_cake(0,1,0)) num_set.add(hash2(0,1,0)) if z > 1: heapq.heappush(cake_list, maling_cake(0,0,1)) num_set.add(hash2(0,0,1)) else: di, ai, bi, ci = heapq.heappop(cake_list) if ai < x - 1: if hash2(ai+1,bi,ci) not in num_set: heapq.heappush(cake_list, maling_cake(ai+1,bi,ci)) num_set.add(hash2(ai+1,bi,ci)) if bi < y - 1: if hash2(ai,bi+1,ci) not in num_set: heapq.heappush(cake_list, maling_cake(ai,bi+1,ci)) num_set.add(hash2(ai,bi+1,ci)) if ci < z - 1: if hash2(ai,bi,ci+1) not in num_set: heapq.heappush(cake_list, maling_cake(ai,bi,ci+1)) num_set.add(hash2(ai,bi,ci+1)) print((-di))
p03078
ma = lambda :map(int,input().split()) lma = lambda :list(map(int,input().split())) tma = lambda :tuple(map(int,input().split())) ni = lambda:int(input()) yn = lambda fl:print("Yes") if fl else print("No") import collections import math import itertools import heapq as hq ceil = math.ceil x,y,z,k = ma() A = lma() B=lma() C=lma() AB = [a+b for a in A for b in B] AB.sort(reverse=True) C.sort(reverse=True) ans=[] iab=min(k,x*y) ic=min(k,z) for i in range(ic): for j in range(iab): ans.append(AB[j]+C[i]) ans.sort(reverse=True) for i in range(k): print(ans[i])
ma = lambda :map(int,input().split()) lma = lambda :list(map(int,input().split())) tma = lambda :tuple(map(int,input().split())) ni = lambda:int(input()) yn = lambda fl:print("Yes") if fl else print("No") import collections import math import itertools import heapq as hq ceil = math.ceil x,y,z,k = ma() A = lma() B=lma() C=lma() A.sort(reverse=True) B.sort(reverse=True) C.sort(reverse=True) i,j,m = 0,0,0 h=[(-A[i]-B[j]-C[m],i,j,m)] cnt=0 d=collections.defaultdict(lambda:True) while cnt<k: ans,i,j,m=hq.heappop(h) print(-ans) if i+1<x and d[(i+1,j,m)]: hq.heappush(h,(-A[i+1]-B[j]-C[m],i+1,j,m)) d[(i+1,j,m)]=False if j+1<y and d[(i,j++1,m)]: hq.heappush(h,(-A[i]-B[j+1]-C[m],i,j+1,m)) d[(i,j+1,m)]=False if m+1<z and d[(i,j,m+1)]: hq.heappush(h,(-A[i]-B[j]-C[m+1],i,j,m+1)) d[(i,j,m+1)]=False cnt+=1
p03078
from bisect import bisect_left X,Y,Z,K=list(map(int,input().split())) A=list(map(int,input().split())) B=list(map(int,input().split())) C=list(map(int,input().split())) if X*Y*Z <= 10**10: D = sorted([A[i]+B[j]+C[k] for i in range(X) for j in range(Y) for k in range(Z)],reverse=True) for i in range(K): print((D[i])) else: A = sorted(A) D = sorted([B[i]+C[j] for i in range(Y) for j in range(Z)]) thr = K s = A[-1]+D[max(0,len(D)-thr)] prev_idx=0 selected = [A[-1] + D[i] for i in range(len(D))] for i in range(1,X): r = s - A[-1-i] if r<=0:break idx = bisect_left(D,r,prev_idx,len(D)-1) if idx == len(D):break selected.extend([A[-1-i] + D[j] for j in range(idx,len(D))]) prec_idx = idx selected = sorted(selected,reverse=True) print((len(selected))) for i in range(K): print((selected[i]))
from bisect import bisect_left X,Y,Z,K=list(map(int,input().split())) A=list(map(int,input().split())) B=list(map(int,input().split())) C=list(map(int,input().split())) if X*Y*Z <= 50000: D = sorted([A[i]+B[j]+C[k] for i in range(X) for j in range(Y) for k in range(Z)],reverse=True) for i in range(K): print((D[i])) else: A = sorted(A) D = sorted([B[i]+C[j] for i in range(Y) for j in range(Z)]) thr = K s = A[-1]+D[max(0,len(D)-thr)] prev_idx=0 selected = [A[-1] + D[i] for i in range(max(0,len(D)-thr),len(D))] for i in range(1,X): r = s - A[-1-i] if r<=0:break idx = bisect_left(D,r,prev_idx,len(D)-1) if idx == len(D):break selected.extend([A[-1-i] + D[j] for j in range(idx,len(D))]) prec_idx = idx selected = sorted(selected,reverse=True) for i in range(K): print((selected[i]))
p03078
x, y, z, k = list(map(int, input().split())) a = list(map(int, input().split())) b = list(map(int, input().split())) c = list(map(int, input().split())) a.sort(reverse=True) b.sort(reverse=True) c.sort(reverse=True) d = [] for e1 in a: for e2 in b: d.append(e1+e2) d.sort(reverse=True) d = d[:k] e = [] for e1 in d: for e2 in c: e.append(e1+e2) e.sort(reverse=True) for i in range(k): print((e[i]))
x, y, z, k = list(map(int, input().split())) a = list(map(int, input().split())) b = list(map(int, input().split())) c = list(map(int, input().split())) a.sort(reverse=True) b.sort(reverse=True) c.sort(reverse=True) d = [e1+e2 for e1 in a for e2 in b] d.sort(reverse=True) d = d[:k] e = [e1+e2 for e1 in d for e2 in c] e.sort(reverse=True) for i in range(k): print((e[i]))
p03078
x, y, z, k = list(map(int, input().split())) a = list(map(int, input().split())) b = list(map(int, input().split())) c = list(map(int, input().split())) a.sort(reverse=True) b.sort(reverse=True) c.sort(reverse=True) d = [e1+e2 for e1 in a for e2 in b] d.sort(reverse=True) d = d[:k] e = [e1+e2 for e1 in d for e2 in c] e.sort(reverse=True) for i in range(k): print((e[i]))
x, y, z, k = [int(x) for x in input().split()] a = [int(x) for x in input().split()] b = [int(x) for x in input().split()] c = [int(x) for x in input().split()] a.sort(reverse=True) b.sort(reverse=True) c.sort(reverse=True) d = [e1+e2 for e1 in a for e2 in b] d.sort(reverse=True) d = d[:k] e = [e1+e2 for e1 in d for e2 in c] e.sort(reverse=True) for i in range(k): print((e[i]))
p03078
X, Y, Z, K = list(map(int, input().split(" "))) xs = list(map(int, input().split(" "))) ys = list(map(int, input().split(" "))) zs = list(map(int, input().split(" "))) lst = [x + y + z for x in xs for y in ys for z in zs] lst_s = sorted(lst) for i in range(K): print((lst_s[-(i+1)]))
X, Y, Z, K = list(map(int, input().split(" "))) xs = list(map(int, input().split(" "))) ys = list(map(int, input().split(" "))) zs = list(map(int, input().split(" "))) xy = sorted([x+y for x in xs for y in ys], reverse=True)[:K] xyz = sorted([w+z for w in xy for z in zs], reverse=True) for i in range(K): print((xyz[i]))
p03078
import sys import heapq # \n def input(): return sys.stdin.readline().rstrip() def main(): X, Y, Z, K = list(map(int, input().split())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) A.sort(reverse=True) B.sort(reverse=True) C.sort(reverse=True) Q = [] S = set() heapq.heapify(Q) heapq.heappush(Q, (-A[0] - B[0] - C[0], 0, 0, 0)) for i in range(K): m, a, b, c = heapq.heappop(Q) print((-m)) if (a + 1, b, c) not in S and a + 1 < X: heapq.heappush(Q, (-A[a + 1] - B[b] - C[c], a + 1, b, c)) S.add((a + 1, b, c)) if (a, b + 1, c) not in S and b + 1 < Y: heapq.heappush(Q, (-A[a] - B[b + 1] - C[c], a, b + 1, c)) S.add((a, b + 1, c)) if (a, b, c + 1) not in S and c + 1 < Z: heapq.heappush(Q, (-A[a ] - B[b] - C[c+1], a, b, c + 1)) S.add((a, b, c + 1)) if __name__ == "__main__": main()
import sys # \n def input(): return sys.stdin.readline().rstrip() def main(): X, Y, Z, K = list(map(int, input().split())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) A.sort(reverse=True) B.sort(reverse=True) C.sort(reverse=True) L = [] for i in range(X): for j in range(min(Y, K // (i + 1) + 1)): for k in range(min(Z, K // (i + 1) // (j + 1) + 1)): L.append(A[i] + B[j] + C[k]) L.sort(reverse=True) for i in range(K): print((L[i])) if __name__ == "__main__": main()
p03078
x,y,z,k = list(map(int,input().split())) a = list(map(int,input().split())) b = list(map(int,input().split())) c = list(map(int,input().split())) ab = [] ans = [] for i in range(x): for j in range(y): ab.append(a[i]+b[j]) ab.sort(reverse=True) if len(ab) < k: for i in range(len(ab)): for j in range(z): ans.append(ab[i]+c[j]) else: for i in range(k): for j in range(z): ans.append(ab[i]+c[j]) ans.sort(reverse=True) for i in range(k): print((ans[i]))
x,y,z,k = list(map(int,input().split())) a = list(map(int,input().split())) b = list(map(int,input().split())) c = list(map(int,input().split())) mid = [] for i in range(x): for j in range(y): mid.append(a[i]+b[j]) mid.sort(reverse=True) ans = [] for i in range(min(k,len(mid))): for j in range(z): ans.append(mid[i]+c[j]) ans.sort(reverse=True) for i in range(k): print((ans[i]))
p03078
X, Y, Z, K = list(map(int, input().split())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) res = [] for a in range(X): for b in range(Y): res.append(A[a] + B[b]) res.sort(reverse=True) result = [] for r in res: for c in C: result.append(r + c) result.sort(reverse=True) for i in range(K): print((result[i]))
X, Y, Z, K = list(map(int, input().split())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) C.sort(reverse=True) tmp = [] for x in range(X): for y in range(Y): tmp.append(A[x] + B[y]) tmp.sort(reverse=True) res = [] for i in range(min(K, X*Y)): for z in range(Z): res.append(tmp[i] + C[z]) res.sort(reverse=True) for i in range(K): print((res[i]))
p03078
import itertools as it X, Y, Z, K = [int(n) for n in input().strip().split(' ')] A = sorted([int(s) for s in input().strip().split(' ')], reverse=True) B = sorted([int(s) for s in input().strip().split(' ')], reverse=True) C = sorted([int(s) for s in input().strip().split(' ')], reverse=True) AB_best = sorted([sum(e) for e in it.product(A, B)], reverse=True)[:K] best = sorted([sum(e) for e in it.product(AB_best, C)], reverse=True)[:K] for s in best: print(s)
X, Y, Z, K = [int(n) for n in input().strip().split(' ')] A = sorted([int(s) for s in input().strip().split(' ')], reverse=True) B = sorted([int(s) for s in input().strip().split(' ')], reverse=True) C = sorted([int(s) for s in input().strip().split(' ')], reverse=True) ABC = [] for i, a in enumerate(A): for j, b in enumerate(B): if (i + 1) * (j + 1) > K: break for k, c in enumerate(C): if (i + 1) * (j + 1) * (k + 1) > K: break ABC.append(a + b + c) ABC.sort(reverse=True) for s in ABC[:K]: print(s)
p03078
x, y, z, k = list(map(int, input().split(' '))) a = list(map(int, input().split(' '))) b = list(map(int, input().split(' '))) c = list(map(int, input().split(' '))) ab = [] for i in a: for j in b: ab.append(i+j) ab.sort(reverse = True) abc = [] k_1 = min([len(ab), k]) for i in ab: for j in c: abc.append(i+j) abc.sort(reverse = True) for i in range(k): print((abc[i]))
x, y, z, k = list(map(int, input().split(' '))) a = list(map(int, input().split(' '))) b = list(map(int, input().split(' '))) c = list(map(int, input().split(' '))) ab = [] for i in a: for j in b: ab.append(i+j) ab.sort(reverse = True) abc = [] ab = ab[:k+1] k_1 = min([len(ab), k]) for i in ab: for j in c: abc.append(i+j) abc.sort(reverse = True) for i in range(k): print((abc[i]))
p03078
import heapq import sys x, y, z, k = list(map(int, input().split())) a, b, c = (sorted(map(int, sys.stdin.readline().split()), reverse=True) for _ in range(3)) abc = [[[0 for _ in range(z)] for __ in range(y)] for ___ in range(x)] stu = [[-a[0]-b[0]-c[0], 0,0,0]] heapq.heapify(stu) result = [] while k > 0: out_p, n, m, l = heapq.heappop(stu) if n+1<x and abc[n+1][m][l]==0: abc[n+1][m][l]=1 heapq.heappush(stu, [-a[n+1]-b[m]-c[l], n+1, m, l]) if m+1<y and abc[n][m+1][l]==0: abc[n][m+1][l]=1 heapq.heappush(stu, [-a[n]-b[m+1]-c[l], n, m+1, l]) if l+1<z and abc[n][m][l+1]==0: abc[n][m][l+1]=1 heapq.heappush(stu, [-a[n]-b[m]-c[l+1], n, m, l+1]) result.append(-out_p) k -= 1 result.sort(reverse=True) for i in result: print(i)
import heapq import sys x, y, z, k = list(map(int, input().split())) a, b, c = (sorted(map(int, sys.stdin.readline().split()), reverse=True) for _ in range(3)) abc = {(0,0,0)} stu = [[-a[0]-b[0]-c[0], 0,0,0]] heapq.heapify(stu) result = [] while k > 0: out_p, n, m, l = heapq.heappop(stu) if n+1<x and not((n+1,m,l) in abc): abc.add((n+1,m,l)) heapq.heappush(stu, [-a[n+1]-b[m]-c[l], n+1, m, l]) if m+1<y and not((n,m+1,l) in abc): abc.add((n,m+1,l)) heapq.heappush(stu, [-a[n]-b[m+1]-c[l], n, m+1, l]) if l+1<z and not((n,m,l+1) in abc): abc.add((n,m,l+1)) heapq.heappush(stu, [-a[n]-b[m]-c[l+1], n, m, l+1]) result.append(-out_p) k -= 1 result.sort(reverse=True) for i in result: print(i)
p03078
x, y, z, k = list(map(int,input().split())) alist = [int(i) for i in input().split()] blist = [int(i) for i in input().split()] clist = [int(i) for i in input().split()] # print(x,y,z,k, alist, blist, clist) #%% # x,y,z,k,alist,blist,clist = 2, 2, 2, 8, [4, 6],[1, 5],[3, 8] #%% alist.sort() blist.sort() clist.sort() alist = alist[::-1][:k] blist = blist[::-1][:k] clist = clist[::-1][:k] #%% import itertools #%% ans = [] for i in list(itertools.product(alist, blist, clist)): ans.append((sum(i))) ans.sort() #%% for i in ans[::-1][:k]: print(i) #%%
# https://atcoder.jp/contests/abc123/tasks/abc123_d def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(): return list(map(int, input().split())) X, Y, Z, K = MAP() A = LIST() B = LIST() C = LIST() # A.sort(reverse=True); B.sort(reverse=True); C.sort(reverse=True) E = [] for a in A: for b in B: E.append(a+b) # E.sort(reverse=True) ans = [] for c in C: for e in E: ans.append(c+e) ans.sort(reverse=True) for i, a in enumerate(ans): if i < K: print(a) else: break
p03078
from heapq import heappush, heappop X, Y, Z, K = list(map(int, input().split())) 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) cake_heap = [] for i in range(len(A)): if i + 1 > K: break for j in range(len(B)): if (i + 1) * (j + 1) > K: break for k in range(len(C)): if (i + 1) * (j + 1) * (k + 1) > K: break heappush(cake_heap, -(A[i] + B[j] + C[k])) for i in range(K): print((-heappop(cake_heap)))
from heapq import heappush, heappop X, Y, Z, K = list(map(int, input().split())) 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) h = [] minus_value = -(A[0] + B[0] + C[0]) heappush(h, (minus_value, 0, 0, 0)) searched = set() cnt = 0 while cnt < K: minus_value, ia, ib, ic = heappop(h) if (ia, ib, ic) in searched: continue cnt += 1 searched.add((ia, ib, ic)) print((-minus_value)) if ia < X - 1: heappush(h, (minus_value + A[ia] - A[ia + 1], ia + 1, ib, ic)) if ib < Y - 1: heappush(h, (minus_value + B[ib] - B[ib + 1], ia, ib + 1, ic)) if ic < Z - 1: heappush(h, (minus_value + C[ic] - C[ic + 1], ia, ib, ic + 1))
p03078
X, Y, Z, K = list(map(int, input().split())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) AB = [] for i in range(len(A)) : for j in range(len(B)) : AB.append(A[i] + B[j]) AB.sort(reverse = True) AB = AB[:K] ABC = [] for i in range(len(AB)) : for j in range(len(C)) : ABC.append(AB[i] + C[j]) ABC.sort(reverse = True) for i in range(K) : print((ABC[i]))
X, Y, Z, K = list(map(int, input().split())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) AB = [0] *(len(A) * len(B)) for i in range(len(A)) : for j in range(len(B)) : AB[len(B) * i + j] = A[i] + B[j] AB.sort(reverse = True) AB = AB[:K] ABC = [0] * (len(AB) * len(C)) for i in range(len(AB)) : for j in range(len(C)) : ABC[len(B) * i + j] = AB[i] + C[j] ABC.sort(reverse = True) for i in range(K) : print((ABC[i]))
p03078
import sys sys.setrecursionlimit(2147483647) INF=float("inf") MOD=10**9+7 input=lambda :sys.stdin.readline().rstrip() def resolve(): x,y,z,k=list(map(int,input().split())) A=list(map(int,input().split())) B=list(map(int,input().split())) C=list(map(int,input().split())) A.sort(reverse=1) B.sort(reverse=1) C.sort(reverse=1) A=A[:k] B=B[:k] C=C[:k] S=[] from itertools import product for i,j,l in product(list(range(k)),repeat=3): if(i>=x or j>=y or l>=z): continue S.append(A[i]+B[j]+C[l]) S.sort(reverse=1) for i in range(k): print((S[i])) resolve()
import sys sys.setrecursionlimit(2147483647) INF=float("inf") MOD=10**9+7 input=lambda :sys.stdin.readline().rstrip() def resolve(): x,y,z,k=list(map(int,input().split())) A=list(map(int,input().split())) B=list(map(int,input().split())) C=list(map(int,input().split())) S=[] T=[] from itertools import product for a,b in product(A,B): S.append(a+b) S.sort(reverse=1) S=S[:k] for s,c in product(S,C): T.append(s+c) T.sort(reverse=1) for i in range(k): print((T[i])) resolve()
p03078
import sys sys.setrecursionlimit(2147483647) INF=float("inf") MOD=10**9+7 input=lambda :sys.stdin.readline().rstrip() def resolve(): x,y,z,k=list(map(int,input().split())) A=list(map(int,input().split())) B=list(map(int,input().split())) C=list(map(int,input().split())) S=[] T=[] from itertools import product for a,b in product(A,B): S.append(a+b) S.sort(reverse=1) S=S[:k] for s,c in product(S,C): T.append(s+c) T.sort(reverse=1) for i in range(k): print((T[i])) resolve()
import sys sys.setrecursionlimit(2147483647) INF=float("inf") MOD=10**9+7 input=lambda :sys.stdin.readline().rstrip() def resolve(): x,y,z,K=list(map(int,input().split())) A=sorted(map(int,input().split()),reverse=1) B=sorted(map(int,input().split()),reverse=1) C=sorted(map(int,input().split()),reverse=1) # 1<=i<=x,1<=j<=y,1<=k<=z のうち、ijk<=Kを全て取得する from itertools import product ind=[] for i in range(1,x+1): if(i>K): break for j in range(1,y+1): if(i*j>K): break for k in range(1,z+1): if(i*j*k>K): break ind.append((i-1,j-1,k-1)) S=[] for i,j,k in ind: S.append(A[i]+B[j]+C[k]) S.sort(reverse=1) for i in range(K): print((S[i])) resolve()
p03078
import heapq X, Y, Z, K = list(map(int, 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.sort() B.sort() C.sort() queue = [(A[0]+B[0]+C[0], 0, 0, 0)] flg = [[[0 for i in range(Z)] for j in range(Y)] for k in range(X)] flg[0][0][0] = 1 for i in range(K): cake, a, b, c = heapq.heappop(queue) print((-cake)) for j in range(3): aa = a + [1, 0, 0][j] bb = b + [0, 1, 0][j] cc = c + [0, 0, 1][j] if aa < X and bb < Y and cc < Z: if flg[aa][bb][cc] == 0: flg[aa][bb][cc] = 1 heapq.heappush(queue, (A[aa]+B[bb]+C[cc], aa, bb, cc))
import heapq X, Y, Z, K = list(map(int, 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.sort() B.sort() C.sort() queue = [(A[0]+B[0]+C[0], 0, 0, 0)] flg = {} for i in range(K): cake, a, b, c = heapq.heappop(queue) print((-cake)) for j in range(3): aa = a + [1, 0, 0][j] bb = b + [0, 1, 0][j] cc = c + [0, 0, 1][j] if aa < X and bb < Y and cc < Z: if flg.get((aa, bb, cc)) is None: flg[aa, bb, cc] = 1 heapq.heappush(queue, (A[aa]+B[bb]+C[cc], aa, bb, cc))
p03078
X, Y, Z, K = list(map(int, 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()] AB = sorted([a + b for a in A for b in B], reverse=True)[:K] ABC = sorted([ab + c for ab in AB for c in C], reverse=True)[:K] for a in ABC: print(a)
X, Y, Z, K = list(map(int, input().split())) A = sorted([int(i) for i in input().split()], reverse=True) B = sorted([int(i) for i in input().split()], reverse=True) C = sorted([int(i) for i in input().split()], reverse=True) a = [] for x in range(X): for y in range(Y): for z in range(Z): if ((x + 1) * (y + 1) * (z + 1) <= K): a.append(A[x] + B[y] + C[z]) else: break for b in sorted(a, reverse=True)[:K]: print(b)
p03078
import heapq X, Y, Z, K = list(map(int, input().split())) A = sorted([int(i) for i in input().split()], reverse=True) B = sorted([int(i) for i in input().split()], reverse=True) C = sorted([int(i) for i in input().split()], reverse=True) h = [] heapq.heappush(h, (-(A[0] + B[0] + C[0]), (0, 0, 0))) ans = [] for _ in range(K): p, v = heapq.heappop(h) i, j, k = v ans.append(p) if i + 1 < X and j < Y and k < Z and not (-(A[i+1] + B[j] + C[k]), (i+1, j, k)) in h: heapq.heappush(h, (-(A[i + 1] + B[j] + C[k]), (i+1, j, k))) if i < X and j + 1 < Y and k < Z and not (-(A[i] + B[j+1] + C[k]), (i, j+1, k)) in h: heapq.heappush(h, (-(A[i] + B[j+1] + C[k]), (i, j+1, k))) if i < X and j < Y and k + 1 < Z and not (-(A[i] + B[j] + C[k+1]), (i, j, k+1)) in h: heapq.heappush(h, (-(A[i] + B[j] + C[k+1]), (i, j, k+1))) for a in ans: print((-a))
import heapq X, Y, Z, K = list(map(int, input().split())) A = sorted([int(i) for i in input().split()], reverse=True) B = sorted([int(i) for i in input().split()], reverse=True) C = sorted([int(i) for i in input().split()], reverse=True) h = [] heapq.heappush(h, (-(A[0] + B[0] + C[0]), (0, 0, 0))) ans = [] e = set() for _ in range(K): p, v = heapq.heappop(h) i, j, k = v ans.append(p) if i + 1 < X and j < Y and k < Z and not (-(A[i+1] + B[j] + C[k]), (i+1, j, k)) in e: heapq.heappush(h, (-(A[i + 1] + B[j] + C[k]), (i+1, j, k))) e.add((-(A[i + 1] + B[j] + C[k]), (i+1, j, k))) if i < X and j + 1 < Y and k < Z and not (-(A[i] + B[j+1] + C[k]), (i, j+1, k)) in e: heapq.heappush(h, (-(A[i] + B[j+1] + C[k]), (i, j+1, k))) e.add((-(A[i] + B[j+1] + C[k]), (i, j+1, k))) if i < X and j < Y and k + 1 < Z and not (-(A[i] + B[j] + C[k+1]), (i, j, k+1)) in e: heapq.heappush(h, (-(A[i] + B[j] + C[k+1]), (i, j, k+1))) e.add((-(A[i] + B[j] + C[k+1]), (i, j, k+1))) for a in ans: print((-a))
p03078
X,Y,Z,K = list(map(int,input().split(' '))) A = list(map(int, input().split(' '))) B = list(map(int, input().split(' '))) C = list(map(int, input().split(' '))) list.sort(A, reverse=True) list.sort(B, reverse=True) list.sort(C, reverse=True) sums = [] for i in range(X): for j in range(Y): for k in range(Z): if (i+1)*(j+1)*(k+1) <= K: sums.append(A[i]+B[j]+C[k]) list.sort(sums, reverse=True) for i in range(K): print((sums[i]))
X,Y,Z,K = list(map(int,input().split(' '))) A = list(map(int, input().split(' '))) B = list(map(int, input().split(' '))) C = list(map(int, input().split(' '))) list.sort(A, reverse=True) list.sort(B, reverse=True) list.sort(C, reverse=True) sums = [] for i in range(X): for j in range(Y): for k in range(Z): if (i+1)*(j+1)*(k+1) > K: break sums.append(A[i]+B[j]+C[k]) for a in sorted(sums, reverse=True)[:K]: print(a)
p03078
def main(): X, Y, Z, K = list(map(int, input().split())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) A.sort(reverse = True) B.sort(reverse = True) C.sort(reverse = True) A += [-1e10] B += [-1e10] C += [-1e10] memo = [A[i] + B[0] + C[0] for i in range(X + 1)] L = [[0 for i in range(Y + 1)] for j in range(X + 1)] for i in range(K): ma = 0 for j in range(X): if memo[ma] < memo[j]: ma = j print((memo[ma])) mb = 0 mn = 0 for j in range(Y): x = B[j] + C[L[ma][j]] if mb < x: mb = x mn = j L[ma][mn] += 1 n = 0 for j in range(Y): n = max(n, B[j] + C[L[ma][j]]) memo[ma] = A[ma] + n main()
X, Y, Z, K = list(map(int, input().split())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) A.sort(reverse = True) B.sort(reverse = True) C.sort(reverse = True) abc = [] for i in range(X): for j in range(Y): if (i + 1) * (j + 1) > K: break for k in range(Z): if (i + 1) * (j + 1) * (k + 1) > K: break abc.append(A[i] + B[j] + C[k]) abc.sort(reverse = True) for i in range(K): print((abc[i]))
p03078
import itertools X, Y, Z, K = map(int, input().split()) A = sorted(list(map(int, input().split()))) B = sorted(list(map(int, input().split()))) C = sorted(list(map(int, input().split()))) comb_ab = [] for a, b in itertools.product(A, B): comb_ab.append(sum([a, b])) comb_ab_top = sorted(comb_ab, reverse=True)[:K] comb_abc = [] for ab, c in itertools.product(comb_ab_top, C): comb_abc.append(sum([ab, c])) ans = sorted(comb_abc, reverse=True)[:K] print(*ans, sep='\n')
X, Y, Z, K = map(int, input().split()) 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) comb = [] for a in range(X): b_max = K // (a+1) for b in range(min(Y, b_max)): c_max = K // ((a+1)*(b+1)) for c in range(min(Z, c_max)): comb.append(sum([A[a], B[b], C[c]])) comb.sort(reverse=True) print(*comb[:K], sep='\n')
p03078
from collections import OrderedDict X, Y, Z, K = list(map(int, input().split())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) A.sort(reverse=True) B.sort(reverse=True) C.sort(reverse=True) max_b = max(B) max_c = max(C) summs_ab = [] summs = [] for a in A: for b in B: summs_ab.append(a+b) summs_ab.sort(reverse=True) summs_ab = summs_ab[0:min(3001, X*Y*Z+1)] for c in C: for sab in summs_ab: summs.append(sab+c) summs.sort(reverse=True) for s in summs[0:K]: print(s)
from collections import OrderedDict X, Y, Z, K = list(map(int, input().split())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) A.sort(reverse=True) B.sort(reverse=True) C.sort(reverse=True) """ max_b = max(B) max_c = max(C) """ summs_ab = [] summs = [] for a in A: for b in B: summs_ab.append(a+b) summs_ab.sort(reverse=True) summs_ab = summs_ab[0:min(3001, X*Y*Z+1)] for c in C: for sab in summs_ab: summs.append(sab+c) summs.sort(reverse=True) """ for a in A[:K]: if len(summs) >= K and a + max_b + max_c < summs[K-1]: break for b in B[:K]: if len(summs) >= K and a + b + max_c < summs[K-1]: break for c in C[:K]: summ = a + b + c if len(summs) >= K: min_sum = summs[K-1] if summ < min_sum: break summs.append(summ) summs = merge_sort(summs) summs.reverse() """ for i in range(K): print((summs[i]))
p03078
x,y,z,k = list(map(int,input().split())) lisa = list(map(int,input().split())) lisb = list(map(int,input().split())) lisc = list(map(int,input().split())) lisa.sort(reverse=True) lisb.sort(reverse=True) lisc.sort(reverse=True) an = [] ans = [] for num in lisb: for nu in lisa: an.append(num+nu) an.sort(reverse=True) an = an[:min(3001,x*y*z+1)] for num in lisc: for nu in an: ans.append(num+nu) ans.sort(reverse=True) for i in range(k): print((ans[i]))
X, Y, Z, K = list(map(int, input().split())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) A.sort(reverse=True) B.sort(reverse=True) C.sort(reverse=True) result = [] for i in range(X): for j in range(Y): for k in range(Z): if (i + 1) * (j + 1) * (k + 1) <= K: result.append(A[i] + B[j] + C[k]) else: break result.sort(reverse=True) for rs in result[:K]: print(rs)
p03078
x,y,z,k=list(map(int,input().split())) 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) a=1 b=1 c=1 A.append(-10**11) B.append(-10**11) C.append(-10**11) A.insert(0,-10**11) B.insert(0,-10**11) C.insert(0,-10**11) print((A[a]+B[b]+C[c])) memo=[[[False]*(z+2) for _ in range(y+2)] for _ in range(x+2)] memo[a][b][c]=True for _ in range(k-1): keepv=0 for a2 in range(1,x+2): for b2 in range(1,y+2): for c2 in range(1,z+2): if not memo[a2][b2][c2]: if A[a2]+B[b2]+C[c2]>keepv: keepv=A[a2]+B[b2]+C[c2] keepa=a2 keepb=b2 keepc=c2 a=keepa b=keepb c=keepc print((A[a]+B[b]+C[c])) #print(a,b,c) #print(memo[2][1][1]) memo[a][b][c]=True
x,y,z,k=list(map(int,input().split())) A=list(map(int,input().split())) B=list(map(int,input().split())) C=list(map(int,input().split())) AB=[] for a in A: for b in B: AB.append(a+b) AB=sorted(AB,reverse=True)[:k] ABC=[] for ab in AB: for c in C: ABC.append(ab+c) ABC.sort(reverse=True) for abc in ABC[:k]: print(abc)
p03078
x, y, z, k = list(map(int, input().split())) a = list(map(int, input().split())) b = list(map(int, input().split())) c = list(map(int, input().split())) a.sort() b.sort() c.sort() from bisect import bisect_left, bisect_right def C(x): # count "abc <= x" ret = 0 for aa in a: for bb in b: idx = bisect_right(c, x - aa - bb) ret += idx return ret kk = x * y * z - k + 1 lb = 0 ub = (10 ** 10) * 4 while ub - lb > 1: mid = (ub + lb) // 2 if C(mid) >= kk: ub = mid else: lb = mid kth = ub l = [] for aa in a: for bb in b: idx = bisect_left(c, kth - aa - bb) # print(aa, bb, idx) for i in range(idx, z): l.append(aa + bb + c[i]) l.sort(reverse=True) for ll in l: print(ll)
if __name__ == '__main__': x, y, z, k = list(map(int, input().split())) a = list(map(int, input().split())) b = list(map(int, input().split())) c = list(map(int, input().split())) bc = [] for bb in b: for cc in c: bc.append(bb + cc) bc.sort() from bisect import bisect_left def C(x): # count "abc >= x" ret = 0 for aa in a: idx = bisect_left(bc, x - aa) ret += len(bc) - idx return ret lb = 0 ub = (10 ** 10) * 3 + 1 while ub - lb > 1: mid = (ub + lb) // 2 if C(mid) >= k: lb = mid else: ub = mid kth = lb l = [] for aa in a: idx = bisect_left(bc, kth - aa) for i in range(idx, len(bc)): l.append(aa + bc[i]) l.sort(reverse=True) l = l[:k] for ll in l: print(ll)
p03078
# coding: utf-8 # Your code here! x,y,z,k = list(map(int,input().split())) A = sorted(map(int,input().split()))[::-1] B = sorted(map(int,input().split()))[::-1] C = sorted(map(int,input().split()))[::-1] AB = sorted([a+b for a in A for b in B])[::-1] ans = sorted([ab + c for ab in AB for c in C])[::-1] for i in ans[:k]: print(i)
# coding: utf-8 # Your code here! x,y,z,k = list(map(int,input().split())) A = sorted(map(int,input().split()))[::-1] B = sorted(map(int,input().split()))[::-1] C = sorted(map(int,input().split()))[::-1] AB = sorted([a+b for a in A for b in B])[::-1] ans = sorted([ab + c for ab in AB[:k] for c in C])[::-1] for i in ans[:k]: print(i)
p03078
x,y,z,k = list(map(int,input().split())) A = sorted(map(int,input().split()))[::-1] B = sorted(map(int,input().split()))[::-1] C = sorted(map(int,input().split()))[::-1] AB = sorted([a+b for a in A for b in B])[::-1] ans = sorted([ab + c for ab in AB[:k] for c in C])[::-1] for i in ans[:k]: print(i)
# coding: utf-8 # Your code here! x,y,z,k = list(map(int,input().split())) A = sorted(map(int,input().split()))[::-1] B = sorted(map(int,input().split()))[::-1] C = sorted(map(int,input().split()))[::-1] AB = [a+b for a in A for b in B] AB.sort(reverse = True) ans = [ab + c for ab in AB[:k] for c in C] ans.sort(reverse = True) for i in ans[:k]: print(i)
p03078
import itertools X, Y, Z, K = list(map(int, input().split())) 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) AB = [] for p in itertools.product(A, B): AB.append(sum(p)) AB = sorted(AB, reverse=True)[:K] l = [] for p in itertools.product(AB, C): l.append(sum(p)) l = sorted(l, reverse=True)[:K] for i in range(K): print((l[i]))
x,y,z,k = list(map(int,input().split())) lisa = list(map(int,input().split())) lisb = list(map(int,input().split())) lisc = list(map(int,input().split())) lisa.sort(reverse=True) lisb.sort(reverse=True) lisc.sort(reverse=True) an = [] ans = [] for num in lisb: for nu in lisa: an.append(num+nu) an.sort(reverse=True) an = an[:min(3001,x*y*z+1)] for num in lisc: for nu in an: ans.append(num+nu) ans.sort(reverse=True) for i in range(k): print((ans[i]))
p03078
X, Y, Z, K = list(map(int, input().split())) A = list(map(int, input().split())) A.sort(reverse=True) B = list(map(int, input().split())) B.sort(reverse=True) C = list(map(int, input().split())) C.sort(reverse=True) AB = [] for b in B: for a in A: AB.append(a+b) AB = sorted(AB, reverse=True)[:K] ABC = [] for ab in AB: for c in C: ABC.append(ab+c) ABC.sort(reverse=True) for i in range(K): print((ABC[i]))
X, Y, Z, K = list(map(int, input().split())) A = list(map(int, input().split())) A.sort(reverse=True) B = list(map(int, input().split())) B.sort(reverse=True) C = list(map(int, input().split())) C.sort(reverse=True) AB = [] ABC = [] for b in B: for a in A: AB.append(a+b) AB.sort(reverse=True) # AB = AB[:K] AB = AB[:min(3001, X*Y*Z+1)] for c in C: for ab in AB: ABC.append(ab+c) ABC.sort(reverse=True) for i in range(K): print((ABC[i]))
p03078
X, Y, Z, K = list(map(int, input().split())) A = list(map(int, input().split())) A.sort(reverse=True) B = list(map(int, input().split())) B.sort(reverse=True) C = list(map(int, input().split())) C.sort(reverse=True) AB = [] for b in B: for a in A: AB.append(a+b) AB.sort(reverse=True) AB = AB[:K+1] ABC = [] for c in C: for ab in AB: ABC.append(ab+c) ABC.sort(reverse=True) for i in range(K): print((ABC[i]))
X, Y, Z, K = list(map(int, input().split())) A = list(map(int, input().split())) A.sort(reverse=True) B = list(map(int, input().split())) B.sort(reverse=True) C = list(map(int, input().split())) C.sort(reverse=True) ABC = [] for xi in range(X): if xi+1 > K: break for yi in range(Y): if (xi+1)*(yi+1) > K: break for zi in range(Z): if (xi+1)*(yi+1)*(zi+1) > K: break ABC.append(A[xi]+B[yi]+C[zi]) ABC.sort(reverse=True) for i in range(K): print((ABC[i]))
p03078
#!/usr/bin/env python3 import sys import itertools def solve(X: int, Y: int, Z: int, K: int, A: "List[int]", B: "List[int]", C: "List[int]"): A.sort(reverse=True) B.sort(reverse=True) C.sort(reverse=True) com = list( itertools.product(A,B,C) ) S = list([sum(c) for c in com]) S.sort(reverse=True) for k in range(K): print((S[k])) return # Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template) def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() X = int(next(tokens)) # type: int Y = int(next(tokens)) # type: int Z = int(next(tokens)) # type: int K = int(next(tokens)) # type: int A = [ int(next(tokens)) for _ in range(X) ] # type: "List[int]" B = [ int(next(tokens)) for _ in range(Y) ] # type: "List[int]" C = [ int(next(tokens)) for _ in range(Z) ] # type: "List[int]" solve(X, Y, Z, K, A, B, C) if __name__ == '__main__': main()
#!/usr/bin/env python3 import sys import itertools def solve(X: int, Y: int, Z: int, K: int, A: "List[int]", B: "List[int]", C: "List[int]"): A.sort(reverse=True) B.sort(reverse=True) C.sort(reverse=True) AB = list( itertools.product(A,B) ) ABS = list([sum(c) for c in AB]) ABS.sort(reverse=True) ABS2 = ABS[0:K] ABC = list( itertools.product(ABS2,C) ) ABCS = list([sum(c) for c in ABC]) ABCS.sort(reverse=True) for k in range(K): print((ABCS[k])) # Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template) def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() X = int(next(tokens)) # type: int Y = int(next(tokens)) # type: int Z = int(next(tokens)) # type: int K = int(next(tokens)) # type: int A = [ int(next(tokens)) for _ in range(X) ] # type: "List[int]" B = [ int(next(tokens)) for _ in range(Y) ] # type: "List[int]" C = [ int(next(tokens)) for _ in range(Z) ] # type: "List[int]" solve(X, Y, Z, K, A, B, C) if __name__ == '__main__': main()
p03078
#!/usr/bin/env python3 import sys import itertools def solve(X: int, Y: int, Z: int, K: int, A: "List[int]", B: "List[int]", C: "List[int]"): AB = list( itertools.product(A,B) ) ABS = list([sum(c) for c in AB]) ABS.sort(reverse=True) ABS2 = ABS[0:K] ABC = list( itertools.product(ABS2,C) ) ABCS = list([sum(c) for c in ABC]) ABCS.sort(reverse=True) for k in range(K): print((ABCS[k])) # Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template) def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() X = int(next(tokens)) # type: int Y = int(next(tokens)) # type: int Z = int(next(tokens)) # type: int K = int(next(tokens)) # type: int A = [ int(next(tokens)) for _ in range(X) ] # type: "List[int]" B = [ int(next(tokens)) for _ in range(Y) ] # type: "List[int]" C = [ int(next(tokens)) for _ in range(Z) ] # type: "List[int]" solve(X, Y, Z, K, A, B, C) if __name__ == '__main__': main()
#!/usr/bin/env python3 import sys import itertools def solve(X: int, Y: int, Z: int, K: int, A: "List[int]", B: "List[int]", C: "List[int]"): A.sort(reverse=True) B.sort(reverse=True) C.sort(reverse=True) ABC = [] for x in range(X): for y in range(Y): if ((x+1)*(y+1)) > K: break for z in range(Z): if ((x+1)*(y+1)*(z+1)) > K: break ABC.append(A[x]+B[y]+C[z]) ABC.sort(reverse=True) for k in range(K): print((ABC[k])) # Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template) def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() X = int(next(tokens)) # type: int Y = int(next(tokens)) # type: int Z = int(next(tokens)) # type: int K = int(next(tokens)) # type: int A = [ int(next(tokens)) for _ in range(X) ] # type: "List[int]" B = [ int(next(tokens)) for _ in range(Y) ] # type: "List[int]" C = [ int(next(tokens)) for _ in range(Z) ] # type: "List[int]" solve(X, Y, Z, K, A, B, C) if __name__ == '__main__': main()
p03078
x, y, z, K = list(map(int, input().split())) 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) ans = [] check = [[[False for i in range(K)] for j in range(K)] for k in range(K)] q = [[0, 0, 0, 0]] check[0][0][0] = True while len(q) > 0: i, j, k, step = q.pop(0) if step < min(K, 3000): ans.append(a[i]+b[j]+c[k]) if i+1 < x: if not check[i+1][j][k]: check[i+1][j][k] = True q.append([i+1, j, k, step+1]) if j+1 < y: if not check[i][j+1][k]: check[i][j+1][k] = True q.append([i, j+1, k, step+1]) if k+1 < z: if not check[i][j][k+1]: check[i][j][k+1] = True q.append([i, j, k+1, step+1]) ans = sorted(ans, reverse=True) for i in range(K): print((ans[i]))
import sys input = sys.stdin.readline def main(): x, y, z, K = list(map(int, input().split())) 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) ind = [] for i in range(x): for j in range(y): if (i+1)*(j+1) <= K: for k in range(z): if (i+1)*(j+1)*(k+1) <= K: ind.append(A[i]+B[j]+C[k]) else: break else: break ind = sorted(ind, reverse=True) for i in range(K): print((ind[i])) if __name__ == "__main__": main()
p03078
x, y, z, k = list(map(int,input().split())) *a, = list(map(int,input().split())) *b, = list(map(int,input().split())) *c, = list(map(int,input().split())) a.sort(reverse=True) b.sort(reverse=True) c.sort(reverse=True) l1 = [] for i in a: for j in b: l1.append(i+j) #print(l1) l2 = [] l1.sort(reverse=True) for l in l1: for m in c: l2.append(l+m) #print(l2) l2.sort(reverse=True) for n in range(k): print((l2[n]))
x, y, z, k = list(map(int,input().split())) *a, = list(map(int,input().split())) *b, = list(map(int,input().split())) *c, = list(map(int,input().split())) a.sort(reverse=True) b.sort(reverse=True) c.sort(reverse=True) l1 = [] for i in a: for j in b: l1.append(i+j) #print(l1) l2 = [] l1.sort(reverse=True) for l in range(len(l1[:k])): for m in c: l2.append(l1[l]+m) #print(l2) l2.sort(reverse=True) for n in range(k): print((l2[n]))
p03078
from itertools import product X, Y, Z, K = list(map(int, input().split())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) A.sort(reverse=True) B.sort(reverse=True) C.sort(reverse=True) candidates = [] for i, j, k in product(list(range(len(A))), list(range(len(B))), list(range(len(C)))): if i * j * k <= K: candidates.append(A[i] + B[j] + C[k]) candidates.sort(reverse=True) for c in candidates[:K]: print(c)
X, Y, Z, K = list(map(int, input().split())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) A.sort(reverse=True) B.sort(reverse=True) C.sort(reverse=True) candidates = [] for i in range(len(A)): for j in range(len(B)): for k in range(len(C)): if (i+1) * (j+1) * (k+1) <= K: candidates.append(A[i] + B[j] + C[k]) else: break candidates.sort(reverse=True) for c in candidates[:K]: print(c)
p03078
# -*- coding: utf-8 -*- ############# # Libraries # ############# import sys input = sys.stdin.readline import math #from math import gcd import bisect import heapq from collections import defaultdict from collections import deque from collections import Counter from functools import lru_cache ############# # Constants # ############# MOD = 10**9+7 INF = float('inf') AZ = "abcdefghijklmnopqrstuvwxyz" ############# # Functions # ############# ######INPUT###### def I(): return int(input().strip()) def S(): return input().strip() def IL(): return list(map(int,input().split())) def SL(): return list(map(str,input().split())) def ILs(n): return list(int(eval(input())) for _ in range(n)) def SLs(n): return list(input().strip() for _ in range(n)) def ILL(n): return [list(map(int, input().split())) for _ in range(n)] def SLL(n): return [list(map(str, input().split())) for _ in range(n)] ######OUTPUT###### def P(arg): print(arg); return def Y(): print("Yes"); return def N(): print("No"); return def E(): exit() def PE(arg): print(arg); exit() def YE(): print("Yes"); exit() def NE(): print("No"); exit() #####Shorten##### def DD(arg): return defaultdict(arg) #####Inverse##### def inv(n): return pow(n, MOD-2, MOD) ######Combination###### kaijo_memo = [] def kaijo(n): if(len(kaijo_memo) > n): return kaijo_memo[n] if(len(kaijo_memo) == 0): kaijo_memo.append(1) while(len(kaijo_memo) <= n): kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD) return kaijo_memo[n] gyaku_kaijo_memo = [] def gyaku_kaijo(n): if(len(gyaku_kaijo_memo) > n): return gyaku_kaijo_memo[n] if(len(gyaku_kaijo_memo) == 0): gyaku_kaijo_memo.append(1) while(len(gyaku_kaijo_memo) <= n): gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD) return gyaku_kaijo_memo[n] def nCr(n,r): if n == r: return 1 if n < r or r < 0: return 0 ret = 1 ret = ret * kaijo(n) % MOD ret = ret * gyaku_kaijo(r) % MOD ret = ret * gyaku_kaijo(n-r) % MOD return ret ######Factorization###### def factorization(n): arr = [] temp = n for i in range(2, int(-(-n**0.5//1))+1): if temp%i==0: cnt=0 while temp%i==0: cnt+=1 temp //= i arr.append([i, cnt]) if temp!=1: arr.append([temp, 1]) if arr==[]: arr.append([n, 1]) return arr #####MakeDivisors###### def make_divisors(n): divisors = [] for i in range(1, int(n**0.5)+1): if n % i == 0: divisors.append(i) if i != n // i: divisors.append(n//i) return divisors #####MakePrimes###### def make_primes(N): max = int(math.sqrt(N)) seachList = [i for i in range(2,N+1)] primeNum = [] while seachList[0] <= max: primeNum.append(seachList[0]) tmp = seachList[0] seachList = [i for i in seachList if i % tmp != 0] primeNum.extend(seachList) return primeNum #####GCD##### def gcd(a, b): while b: a, b = b, a % b return a #####LCM##### def lcm(a, b): return a * b // gcd (a, b) #####BitCount##### def count_bit(n): count = 0 while n: n &= n-1 count += 1 return count #####ChangeBase##### def base_10_to_n(X, n): if X//n: return base_10_to_n(X//n, n)+[X%n] return [X%n] def base_n_to_10(X, n): return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X)))) def base_10_to_n_without_0(X, n): X -= 1 if X//n: return base_10_to_n_without_0(X//n, n)+[X%n] return [X%n] #####IntLog##### def int_log(n, a): count = 0 while n>=a: n //= a count += 1 return count ############# # Main Code # ############# X,Y,Z,K = IL() A = IL() B = IL() C = IL() A.sort(reverse = True) B.sort(reverse = True) C.sort(reverse = True) ans = [] q = [(-A[0]-B[0]-C[0],0,0,0)] f = [[[0 for z in range(Z)] for y in range(Y)] for x in range(X)] dx = [-1,1,0,0,0,0] dy = [0,0,-1,1,0,0] dz = [0,0,0,0,-1,1,] f[0][0][0] = 1 while K: K -= 1 v,x,y,z = heapq.heappop(q) ans.append(-v) for i in range(6): nx,ny,nz = x+dx[i],y+dy[i],z+dz[i] if nx<0 or nx>=X or ny<0 or ny>=Y or nz<0 or nz>=Z: continue if f[nx][ny][nz]: continue heapq.heappush(q,(-A[nx]-B[ny]-C[nz],nx,ny,nz)) f[nx][ny][nz] = 1 for a in ans: print(a)
# -*- coding: utf-8 -*- ############# # Libraries # ############# import sys input = sys.stdin.readline import math #from math import gcd import bisect import heapq from collections import defaultdict from collections import deque from collections import Counter from functools import lru_cache ############# # Constants # ############# MOD = 10**9+7 INF = float('inf') AZ = "abcdefghijklmnopqrstuvwxyz" ############# # Functions # ############# ######INPUT###### def I(): return int(input().strip()) def S(): return input().strip() def IL(): return list(map(int,input().split())) def SL(): return list(map(str,input().split())) def ILs(n): return list(int(eval(input())) for _ in range(n)) def SLs(n): return list(input().strip() for _ in range(n)) def ILL(n): return [list(map(int, input().split())) for _ in range(n)] def SLL(n): return [list(map(str, input().split())) for _ in range(n)] ######OUTPUT###### def P(arg): print(arg); return def Y(): print("Yes"); return def N(): print("No"); return def E(): exit() def PE(arg): print(arg); exit() def YE(): print("Yes"); exit() def NE(): print("No"); exit() #####Shorten##### def DD(arg): return defaultdict(arg) #####Inverse##### def inv(n): return pow(n, MOD-2, MOD) ######Combination###### kaijo_memo = [] def kaijo(n): if(len(kaijo_memo) > n): return kaijo_memo[n] if(len(kaijo_memo) == 0): kaijo_memo.append(1) while(len(kaijo_memo) <= n): kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD) return kaijo_memo[n] gyaku_kaijo_memo = [] def gyaku_kaijo(n): if(len(gyaku_kaijo_memo) > n): return gyaku_kaijo_memo[n] if(len(gyaku_kaijo_memo) == 0): gyaku_kaijo_memo.append(1) while(len(gyaku_kaijo_memo) <= n): gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD) return gyaku_kaijo_memo[n] def nCr(n,r): if n == r: return 1 if n < r or r < 0: return 0 ret = 1 ret = ret * kaijo(n) % MOD ret = ret * gyaku_kaijo(r) % MOD ret = ret * gyaku_kaijo(n-r) % MOD return ret ######Factorization###### def factorization(n): arr = [] temp = n for i in range(2, int(-(-n**0.5//1))+1): if temp%i==0: cnt=0 while temp%i==0: cnt+=1 temp //= i arr.append([i, cnt]) if temp!=1: arr.append([temp, 1]) if arr==[]: arr.append([n, 1]) return arr #####MakeDivisors###### def make_divisors(n): divisors = [] for i in range(1, int(n**0.5)+1): if n % i == 0: divisors.append(i) if i != n // i: divisors.append(n//i) return divisors #####MakePrimes###### def make_primes(N): max = int(math.sqrt(N)) seachList = [i for i in range(2,N+1)] primeNum = [] while seachList[0] <= max: primeNum.append(seachList[0]) tmp = seachList[0] seachList = [i for i in seachList if i % tmp != 0] primeNum.extend(seachList) return primeNum #####GCD##### def gcd(a, b): while b: a, b = b, a % b return a #####LCM##### def lcm(a, b): return a * b // gcd (a, b) #####BitCount##### def count_bit(n): count = 0 while n: n &= n-1 count += 1 return count #####ChangeBase##### def base_10_to_n(X, n): if X//n: return base_10_to_n(X//n, n)+[X%n] return [X%n] def base_n_to_10(X, n): return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X)))) def base_10_to_n_without_0(X, n): X -= 1 if X//n: return base_10_to_n_without_0(X//n, n)+[X%n] return [X%n] #####IntLog##### def int_log(n, a): count = 0 while n>=a: n //= a count += 1 return count ############# # Main Code # ############# X,Y,Z,K = IL() A = IL() B = IL() C = IL() A.sort(reverse = True) B.sort(reverse = True) C.sort(reverse = True) ans = [] q = [(-A[0]-B[0]-C[0],0,0,0)] f = [0] dx = [-1,1,0,0,0,0] dy = [0,0,-1,1,0,0] dz = [0,0,0,0,-1,1,] while K: K -= 1 v,x,y,z = heapq.heappop(q) ans.append(-v) for i in range(6): nx,ny,nz = x+dx[i],y+dy[i],z+dz[i] if nx<0 or nx>=X or ny<0 or ny>=Y or nz<0 or nz>=Z: continue if (nx*Y*Z + ny*Z + nz) in f: continue heapq.heappush(q,(-A[nx]-B[ny]-C[nz],nx,ny,nz)) f.append(nx*Y*Z + ny*Z + nz) for a in ans: print(a)
p03078
import itertools X, Y, Z, K = list(map(int, input().split())) A = sorted(list(map(int, input().split()))) B = sorted(list(map(int, input().split()))) C = sorted(list(map(int, input().split()))) AB = [a + b for (a, b) in list(itertools.product(A, B))] AB.sort(reverse = True) ans = [ab + c for (ab, c) in list(itertools.product(AB[:K], C))] ans.sort(reverse = True) for i in range(K): print((ans[i]))
X, Y, Z, K = map(int, input().split()) 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) l = [] for a in A: for b in B: l.append(a+b) l = sorted(l, reverse = True)[:K] ans = [] for c in C: for k in l: ans.append(c + k) ans = sorted(ans, reverse = True) print(*ans[:K], sep="\n")
p03078
from bisect import insort X, Y, Z, K = list(map(int, 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.sort(reverse=True) B.sort(reverse=True) C.sort(reverse=True) for i in range(Z-1, 0, -1) : C[i] -= C[i-1] n = [] for x in range(X) : for y in range(Y) : n.append((A[x]+B[y]+C[0], 0)) n.sort() for _ in range(K) : cur, z = n.pop() print(cur) if z < Z - 1 : z += 1 insort(n, (cur+C[z], z))
X, Y, Z, K = list(map(int, 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.sort(reverse=True) B.sort(reverse=True) C.sort(reverse=True) s = [] for x in range(X) : for y in range(Y) : s.append(A[x]+B[y]) s.sort(reverse=True) t = [] for k in range(min(K, len(s))) : for z in range(Z) : t.append(s[k]+C[z]) t.sort(reverse=True) print(("\n".join(map(str, t[:K]))))
p03078
import heapq x,y,z,k = list(map(int,input().split())) a = list(map(int,input().split())) b = list(map(int,input().split())) c = list(map(int,input().split())) l = [] for p in range(0,x): for q in range(0,y): for r in range(0,z): if len(l) > k: heapq.heappushpop(l,a[p]+b[q]+c[r]) else: heapq.heappush(l,a[p]+b[q]+c[r]) l.sort() for i in range(1,k+1): print((l[-i]))
import heapq x,y,z,k = list(map(int,input().split())) a = list(map(int,input().split())) b = list(map(int,input().split())) c = list(map(int,input().split())) a.sort(reverse = True) b.sort(reverse = True) c.sort(reverse = True) l = [] for p in range(0,x): for q in range(0,y): for r in range(0,z): if len(l) > k and a[p]+b[q]+c[r] <= l[0]: break elif len(l) > k: heapq.heappushpop(l,a[p]+b[q]+c[r]) else: heapq.heappush(l,a[p]+b[q]+c[r]) l.sort() for i in range(1,k+1): print((l[-i]))
p03078
x, y, z, k = [int(x) for x in input().split()] A = [int(x) for x in input().split()] B = [int(x) for x in input().split()] C = [int(x) for x in input().split()] A.sort(reverse=True); B.sort(reverse=True); C.sort(reverse=True) ans = [] for i in A: for j in B: for l in C: ans.append(i+j+l) ans.sort(reverse=True) for i in range(k): print((ans[i]))
x, y, z, k = [int(x) for x in input().split()] A = [int(x) for x in input().split()] B = [int(x) for x in input().split()] C = [int(x) for x in input().split()] A.sort(reverse=True); B.sort(reverse=True); C.sort(reverse=True) ans = [] for i in A: for j in B: ans.append(i+j) ans.sort(reverse=True) ans = ans[:k] ans1 = [] for i in C: for j in ans: ans1.append(i+j) ans1.sort(reverse=True) for i in range(k): print((ans1[i]))
p03078
N = list(map(int, input().split()))[-1] A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) first = [i+j for i in A for j in B] first = sorted(first)[::-1] second = [i+j for i in first for j in C] print(("\n".join([str(value) for value in sorted(second)[::-1][:N]])))
N = list(map(int, input().split()))[-1] A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) first = [i+j for i in A for j in B] first = sorted(first)[::-1] second = [first[i]+j for i in range(len(first)) for j in C if i <= N] print(("\n".join([str(value) for value in sorted(second)[::-1][:N]])))
p03078
N = list(map(int, input().split()))[-1] A = sorted(list(map(int, input().split())), reverse=True)[:N] B = sorted(list(map(int, input().split())), reverse=True)[:N] C = sorted(list(map(int, input().split())), reverse=True)[:N] result = [A[i]+B[j]+C[k] for i in range(len(A)) for j in range(len(B)) for k in range(len(C)) if i+j+k <= N ] result = sorted(result, reverse=True) [print(result[i]) for i in range(N)]
N = list(map(int, input().split()))[-1] A = sorted(list(map(int, input().split())), reverse=True)[:N] B = sorted(list(map(int, input().split())), reverse=True)[:N] C = sorted(list(map(int, input().split())), reverse=True)[:N] first = [i+j for i in A for j in B] first = sorted(first, reverse=True)[:N] second = [i+j for i in first for j in C] result = sorted(second, reverse=True)[:N] [print(i) for i in result]
p03078
''' Created on 2020/09/08 @author: harurun ''' def main(): import sys pin=sys.stdin.readline pout=sys.stdout.write perr=sys.stderr.write X,Y,Z,K=list(map(int,pin().split())) A=list(map(int,pin().split())) B=list(map(int,pin().split())) C=list(map(int,pin().split())) # A.sort(reverse=True) # B.sort(reverse=True) # C.sort(reverse=True) d=[] for i in A: for j in B: d.append(i+j) # d.sort(reverse=True) ans=[] for k in d: for l in C: ans.append(k+l) ans.sort(reverse=True) for m in range(K): print((ans[m])) return main()
''' Created on 2020/09/08 @author: harurun ''' def main(): import sys pin=sys.stdin.readline pout=sys.stdout.write perr=sys.stderr.write X,Y,Z,K=list(map(int,pin().split())) A=list(map(int,pin().split())) B=list(map(int,pin().split())) C=list(map(int,pin().split())) # A.sort(reverse=True) # B.sort(reverse=True) # C.sort(reverse=True) d=[] for i in A: for j in B: d.append(i+j) d.sort(reverse=True) d=d[:K] ans=[] for k in d: for l in C: ans.append(k+l) ans.sort(reverse=True) for m in range(K): print((ans[m])) return main()
p03078
X, Y, Z, K = list(map(int, input().split())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) A.sort(reverse = True) B.sort(reverse = True) C.sort(reverse = True) ans = [] ApB = [] for i in range(min(X, K)): for j in range(min(Y, K)): ApB.append(A[i] + B[j]) ApB.sort(reverse = True) for i in range(min(Z, K)): for j in range(min(len(ApB), K)): ans.append(C[i] + ApB[j]) ans.sort(reverse = True) for i in range(K): print((ans[i]))
X, Y, Z, K = list(map(int, input().split())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) A.sort(reverse = True) B.sort(reverse = True) C.sort(reverse = True) ans = [] for i in range(min(X, K)): for j in range(min(Y, K)): if (i + 1) * (j + 1) > K: break for k in range(min(Z, K)): if (i + 1) * (j + 1) * (k + 1) > K: break ans.append(A[i] + B[j] + C[k]) ans.sort(reverse = True) for i in range(K): print((ans[i]))
p03078
x,y,z,k = list(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) AB = [] ABC = [] for i in A: for j in B: AB.append(i+j) AB.sort(reverse = True) AB = AB[:min(3001,x*y*z+1)] for i in AB: for j in C: ABC.append(i+j) ABC.sort(reverse = True) for i in range(k): print((ABC[i]))
x,y,z,k = list(map(int,input().split())) lisa = list(map(int,input().split())) lisb = list(map(int,input().split())) lisc = list(map(int,input().split())) lisa.sort(reverse=True) lisb.sort(reverse=True) lisc.sort(reverse=True) an = [] ans = [] for num in lisb: for nu in lisa: an.append(num+nu) an.sort(reverse=True) an = an[:min(3001,x*y*z+1)] for num in lisc: for nu in an: ans.append(num+nu) ans.sort(reverse=True) for i in range(k): print((ans[i]))
p03078
X, Y, Z, K = list(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)[:K+1] B = sorted(B, reverse=True)[:K+1] C = sorted(C, reverse=True)[:K+1] res = [] for i in A: for j in B: for k in C: res.append(i + j + k) res = sorted(res, reverse=True)[:K+1] for i in range(K): print((res[i]))
X, Y, Z, K = list(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)[:K+1] B = sorted(B, reverse=True)[:K+1] C = sorted(C, reverse=True)[:K+1] res = [] for i in A: for j in B: res.append(i + j) res2 = [] res = sorted(res, reverse=True)[:K+1] for i in C: for re in res: res2.append(i + re) res2 = sorted(res2, reverse=True)[:K+1] for i in range(K): print((res2[i]))
p03078