input
stringlengths
20
127k
target
stringlengths
20
119k
problem_id
stringlengths
6
6
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())) result = [a + b + c for (a,b,c) in list(itertools.product(A, B, C))] result.sort(reverse = True) for i in range(K): print((result[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())) result = [a + b for (a,b) in list(itertools.product(A, B))] result.sort(reverse = True) result = [s + c for (s,c) in list(itertools.product(result[:K], C))] result.sort(reverse = True) for i in range(K): print((result[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) ans = [A[i]+B[j]+C[k] for i in range(X) for j in range(Y) for k in range(Z) if (i+1)*(j+1)*(k+1) <= K] 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) t =[] for i in range(X): for j in range(Y): for k in range(Z): if (i+1)*(j+1)*(k) <= K: t.append(A[i]+B[j]+C[k]) else:break t.sort(reverse=True) for i in range(K): print((t[i]))
p03078
from heapq import nlargest x,y,z,k=list(map(int,input().split())) A,B,C=[list(map(int,input().split()))for _ in[0]*3] E=nlargest(k,(a+b+c for a in A for b in B for c in C)) for i in E: print(i)
from heapq import nlargest x,y,z,k=list(map(int,input().split())) A,B,C=[list(map(int,input().split()))for _ in[0]*3] D=nlargest(k,(a+b for a in A for b in B )) E=nlargest(k,(d+c for c in C for d in D )) for i in E: print(i)
p03078
#coding:utf-8 import sys sys.setrecursionlimit(2**31-1) input = sys.stdin.readline write = sys.stdout.write LMIIS = lambda : list(map(int,input().split())) II = lambda : int(input()) dbg = lambda *something : print(*something) if DEBUG is True else 0 DEBUG = True def main(): X,Y,Z,K = LMIIS() A = LMIIS() B = LMIIS() C = LMIIS() # A.sort(reverse=True) # B.sort(reverse=True) # C.sort(reverse=True) h = [] from heapq import heappush,heappop for a in A: for b in B: for c in C: heappush(h,-(a+b+c)) for _ in range(K): print(-heappop(h)) # A.append(0) # B.append(0) # C.append(0) # # ai = bi = ci = 0 # # for i in range(min(3000,X*Y*Z)): # # print(A[ai],B[bi],C[ci]) # # print(A[ai]+B[bi]+C[ci]) # # nextai = ai + 1 if ai < X else ai # # nextbi = bi + 1 if bi < Y else bi # # nextci = ci + 1 if ci < Z else ci # # #aiを更新する場合 # # if A[nextai] >= B[nextbi]: # # if A[nextai] >= C[nextci]: # # ai = nextai # # else: # # ci = nextci # # else: # # if B[nextbi] >= C[nextci]: # # bi = nextbi # # else: # # ci = nextci pass if __name__ == '__main__': main()
#coding:utf-8 import sys sys.setrecursionlimit(2**31-1) input = sys.stdin.readline write = sys.stdout.write LMIIS = lambda : list(map(int,input().split())) II = lambda : int(input()) dbg = lambda *something : print(*something) if DEBUG is True else 0 DEBUG = True def main(): X,Y,Z,K = LMIIS() A = LMIIS() B = LMIIS() C = LMIIS() AB = [] for a in A: for b in B: AB.append(a+b) AB.sort(reverse=True) ABC = [] for ab in AB[:K]: for c in C: ABC.append(ab+c) ABC.sort(reverse=True) for i in range(K): print(ABC[i]) pass if __name__ == '__main__': main()
p03078
#coding:utf-8 import sys sys.setrecursionlimit(2**31-1) input = sys.stdin.readline write = sys.stdout.write LMIIS = lambda : list(map(int,input().split())) II = lambda : int(input()) dbg = lambda *something : print(*something) if DEBUG is True else 0 DEBUG = True def main(): X,Y,Z,K = LMIIS() A = LMIIS() B = LMIIS() C = LMIIS() AB = [] for a in A: for b in B: AB.append(a+b) AB.sort(reverse=True) ABC = [] for ab in AB[:K]: for c in C: ABC.append(ab+c) ABC.sort(reverse=True) for i in range(K): print(ABC[i]) pass if __name__ == '__main__': main()
#coding:utf-8 import sys sys.setrecursionlimit(2**31-1) input = sys.stdin.readline write = sys.stdout.write LMIIS = lambda : list(map(int,input().split())) II = lambda : int(input()) dbg = lambda *something : print(*something) if DEBUG is True else 0 DEBUG = True def main(): X,Y,Z,K = LMIIS() A = LMIIS() B = LMIIS() C = LMIIS() A.sort(reverse=True) B.sort(reverse=True) C.sort(reverse=True) ans = [] for ai in range(X): for bi in range(Y): if ai * bi > K: break for ci in range(Z): if ai * bi * ci > K: break ans.append(A[ai]+B[bi]+C[ci]) ans.sort(reverse=True) for i in range(K): print(ans[i]) if __name__ == '__main__': main()
p03078
from collections import deque 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())) out = deque() for i in range(X): for j in range(Y): for k in range(Z): out.append(A[i]+B[j]+C[k]) out = list(out) out.sort(reverse = True) for i in range(K): print((out[i]))
from collections import deque 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())) out = deque() out2 = deque() for i in range(X): for j in range(Y): out.append(A[i]+B[j]) out = list(out) out.sort(reverse = True) del out[K:] for i in range(len(out)): for j in range(Z): out2.append(out[i]+C[j]) out2 = list(out2) out2.sort(reverse = True) for i in range(K): print((out2[i]))
p03078
from collections import deque 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())) out = deque() out2 = deque() for i in range(X): for j in range(Y): out.append(A[i]+B[j]) out = list(out) out.sort(reverse = True) del out[K:] for i in range(len(out)): for j in range(Z): out2.append(out[i]+C[j]) out2 = list(out2) out2.sort(reverse = True) for i in range(K): print((out2[i]))
from collections import deque 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())) out = deque() out2 = deque() for i in range(X): for j in range(Y): out.append(A[i]+B[j]) out = sorted(out, reverse=True) del out[K:] for i in range(len(out)): for j in range(Z): out2.append(out[i]+C[j]) out2 = sorted(out2, reverse=True) for i in range(K): print((out2[i]))
p03078
from functools import lru_cache numbers = input().split() x = input().split() y = input().split() z = input().split() k = int(numbers[3]) x.sort(reverse=True) y.sort(reverse=True) z.sort(reverse=True) answer = [] for i in x: for j in y: for m in z: price = int(i)+int(j)+int(m) answer.append(price) answer.sort(reverse=True) del answer[k::] for l in answer: print(l)
numbers = input().split() x = input().split() y = input().split() z = input().split() k = int(numbers[3]) answer = [] for i in x: for j in y: price = int(i)+int(j) answer.append(price) answer.sort(reverse=True) del answer[k::] f_ans = [] for m in answer: for n in z: price = m + int(n) f_ans.append(price) f_ans.sort(reverse=True) del f_ans[k::] for l in f_ans: print(l)
p03078
import sys def input(): return sys.stdin.readline().strip() def mapint(): return list(map(int, input().split())) sys.setrecursionlimit(10**9) X, Y, Z, K = mapint() Xs = list(mapint()) Ys = list(mapint()) Zs = list(mapint()) Xs.sort(reverse=True) Ys.sort(reverse=True) Zs.sort(reverse=True) x, y, z = 0, 0, 0 from heapq import heappop, heappush Q = [] heappush(Q, (-(Xs[x]+Ys[y]+Zs[z]), (x, y, z))) s = set() s.add((x, y, z)) for _ in range(K): ans, (x, y, z) = heappop(Q) print((-ans)) origin = [x, y, z] for i in range(3): xyz = origin[:] xyz[i] += 1 x, y, z = xyz if x>=X or y>=Y or z>=Z: continue if not tuple(xyz) in s: heappush(Q, (-(Xs[x]+Ys[y]+Zs[z]), (x, y, z))) s.add((x, y, z))
import sys def input(): return sys.stdin.readline().strip() def mapint(): return list(map(int, input().split())) sys.setrecursionlimit(10**9) X, Y, Z, K = mapint() As = list(mapint()) Bs = list(mapint()) Cs = list(mapint()) As.sort(reverse=True) Bs.sort(reverse=True) Cs.sort(reverse=True) from heapq import heappop, heappush Q = [] heappush(Q, (-(As[0]+Bs[0]+Cs[0]), 0, 0, 0)) s = set() for _ in range(K): v, a, b, c = heappop(Q) print((-v)) if a+1<X and not (a+1, b, c) in s: s.add((a+1, b, c)) heappush(Q, (-(As[a+1]+Bs[b]+Cs[c]), a+1, b, c)) if b+1<Y and not (a, b+1, c) in s: s.add((a, b+1, c)) heappush(Q, (-(As[a]+Bs[b+1]+Cs[c]), a, b+1, c)) if c+1<Z and not (a, b, c+1) in s: s.add((a, b, c+1)) heappush(Q, (-(As[a]+Bs[b]+Cs[c+1]), a, b, c+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())) res = [] for a in A: for b in B: for c in C: res.append(a + b + c) res.sort(reverse=True) 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())) res = [] for a in A: for b in B: res.append(a + b) res.sort(reverse=True) res2 = [] for v in res[:K]: for c in C: res2.append(v + c) res2.sort(reverse=True) for i in range(K): print((res2[i]))
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) pq = [] heappush(pq, (-A[0] - B[0] - C[0], 0, 0, 0)) appeared = set((0, 0, 0)) for _ in range(K): # Pop maximum value val, i, j, k = heappop(pq) print((-val)) # Add next value if i + 1 < X and (i + 1, j, k) not in appeared: heappush(pq, (-A[i + 1] - B[j] - C[k], i + 1, j, k)) appeared.add((i + 1, j, k)) if j + 1 < Y and (i, j + 1, k) not in appeared: heappush(pq, (-A[i] - B[j + 1] - C[k], i, j + 1, k)) appeared.add((i, j + 1, k)) if k + 1 < Z and (i, j, k + 1) not in appeared: heappush(pq, (-A[i] - B[j] - C[k + 1], i, j, k + 1)) appeared.add((i, j, k + 1))
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) res = [] for i in range(X): for j in range(Y): for k in range(Z): if (i + 1) * (j + 1) * (k + 1) <= K: res.append(A[i] + B[j] + C[k]) else: break res.sort(reverse=True) for i in range(K): print((res[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) ans = [] for i in range(min(K,X)): for j in range(min(K,Y)): for k in range(min(K,Z)): ans.append(A[i]+B[j]+C[k]) ans = sorted(ans, 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 = sorted(A, reverse = True) B = sorted(B, reverse = True) C = sorted(C, reverse = True) ans = [] for i in range(min(K,X)): for j in range(min(K//(i+1),Y)): for k in range(min(K//(i+1)//(j+1),Z)): ans.append(A[i]+B[j]+C[k]) ans = sorted(ans, reverse=True) for i in range(K): print((ans[i]))
p03078
X,Y,Z,K = list(map(int,input().split())) l_a = [int(x) for x in input().split()] l_b = [int(x) for x in input().split()] l_c = [int(x) for x in input().split()] l_a.sort(reverse = True) l_b.sort(reverse = True) l_c.sort(reverse = True) l_d = [a + b for a in l_a for b in l_b] l_d.sort(reverse = True) l_d[:3000] l_e = [ab + c for ab in l_d for c in l_c] l_e.sort(reverse = True) for i in range(K): print((l_e[i]))
X,Y,Z,K = list(map(int,input().split())) l_a = [int(x) for x in input().split()] l_b = [int(x) for x in input().split()] l_c = [int(x) for x in input().split()] l_a.sort(reverse = True) l_b.sort(reverse = True) l_c.sort(reverse = True) l_d = [a + b for a in l_a for b in l_b] l_d.sort(reverse = True) l_d = l_d[:3000] l_e = [ab + c for ab in l_d for c in l_c] l_e.sort(reverse = True) for i in range(K): print((l_e[i]))
p03078
import sys from itertools import product X, Y, Z, K = map(int, input().split()) lst_A = sorted(map(int, input().split()), reverse=True) lst_B = sorted(map(int, input().split()), reverse=True) lst_C = sorted(map(int, input().split()), reverse=True) lst_A_K = lst_A[:K] lst_B_K = lst_B[:K] lst_C_K = lst_C[:K] lst_AB = sorted([a+b for a, b in product(lst_A_K, lst_B_K)], reverse=True) lst_AB_K = lst_AB[:K] lst_ABC = sorted([ab+c for ab, c in product(lst_AB_K, lst_C_K)], reverse=True) lst_ABC_K = lst_ABC[:K] print(*lst_ABC_K, sep="\n")
import sys from itertools import product X, Y, Z, K = map(int, input().split()) lst_A = list(map(int, input().split())) lst_B = list(map(int, input().split())) lst_C = list(map(int, input().split())) lst_A.sort(reverse=True) lst_B.sort(reverse=True) lst_C.sort(reverse=True) # lst_A_K = lst_A[:K] # lst_B_K = lst_B[:K] lst_C_K = lst_C[:K] lst_AB = sorted([a+b for a, b in product(lst_A, lst_B)], reverse=True) lst_AB_K = lst_AB[:K] lst_ABC = sorted([ab+c for ab, c in product(lst_AB_K, lst_C_K)], reverse=True) lst_ABC_K = lst_ABC[:K] print(*lst_ABC_K, sep="\n")
p03078
from itertools import product X, Y, Z, K = list(map(int, input().split())) lst_A = list(map(int, input().split())) lst_B = list(map(int, input().split())) lst_C = list(map(int, input().split())) lst_A.sort(reverse=True) lst_B.sort(reverse=True) lst_C.sort(reverse=True) lst_A_K = lst_A[:K] lst_B_K = lst_B[:K] lst_C_K = lst_C[:K] lst_AB = sorted([a+b for a, b in product(lst_A_K, lst_B_K)], reverse=True) lst_AB_K = lst_AB[:K] lst_ABC = sorted([ab+c for ab, c in product(lst_AB_K, lst_C_K)], reverse=True) lst_ABC_K = lst_ABC[:K] for i in range(K): print((lst_ABC_K[i]))
import sys from itertools import product read = sys.stdin.readline X, Y, Z, K = list(map(int, read().split())) lst_A = list(map(int, read().split())) lst_B = list(map(int, read().split())) lst_C = list(map(int, read().split())) lst_A.sort(reverse=True) lst_B.sort(reverse=True) lst_C.sort(reverse=True) lst_C_K = lst_C[:K] lst_AB = sorted([a+b for a, b in product(lst_A, lst_B)], reverse=True) lst_AB_K = lst_AB[:K] lst_ABC = sorted([ab+c for ab, c in product(lst_AB_K, lst_C_K)], reverse=True) lst_ABC_K = lst_ABC[:K] for i in range(K): print((lst_ABC_K[i]))
p03078
from itertools import product X, Y, Z, K = map(int, input().split()) lst_A = list(map(int, input().split())) lst_B = list(map(int, input().split())) lst_C = list(map(int, input().split())) lst_C = lst_C[:K] lst_AB = [a + b for a, b in product(lst_A, lst_B)] lst_AB.sort(reverse=True) K_ = min(3000, X*Y*Z) lst_ABC = [ab + c for ab, c in list(product(lst_AB[:K_], lst_C))] lst_ABC.sort(reverse=True) print(*lst_ABC[:K], sep="\n")
from itertools import product X, Y, Z, K = map(int, input().split()) lst_A = list(map(int, input().split())) lst_B = list(map(int, input().split())) lst_C = list(map(int, input().split())) lst_A.sort(reverse=True) lst_B.sort(reverse=True) lst_C.sort(reverse=True) lst_C_K = lst_C[:K] lst_AB = sorted([a+b for a, b in product(lst_A, lst_B)], reverse=True) lst_AB_K = lst_AB[:K] lst_ABC = sorted([ab+c for ab, c in product(lst_AB_K, lst_C_K)], reverse=True) lst_ABC_K = lst_ABC[:K] print(*lst_ABC_K, 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) print(*ans[:K],sep='\n')
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())) ab=[] for i in range(x): for j in range(y): ab+=[a[i]+b[j]] ab.sort(key=lambda x: -x) c.sort(key=lambda x: -x) ans=[] ct=[0] ansc=[ab[0]+c[0]] while (len(ans)<k): if(ct[-1]!=0 and len(ct)<z): ansc+=[ab[0]+c[len(ct)]] ct+=[0] ans+=[max(ansc)] tmp=ansc.index(max(ansc)) if(ct[tmp]==len(ab)-1): ansc[tmp]=0 else: ct[tmp]+=1 ansc[tmp]=ab[ct[tmp]]+c[tmp] for i in ans: print(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 range(x): for j in range(y): ab.append(a[i]+b[j]) ab.sort(key=lambda x: -x) c.sort(key=lambda x: -x) ans=[] ct=[0] ansc=[ab[0]+c[0]] while (len(ans)<k): if(ct[-1]!=0 and len(ct)<z): ansc+=[ab[0]+c[len(ct)]] ct+=[0] ans+=[max(ansc)] tmp=ansc.index(max(ansc)) if(ct[tmp]==len(ab)-1): ansc[tmp]=0 else: ct[tmp]+=1 ansc[tmp]=ab[ct[tmp]]+c[tmp] for i in ans: 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())) DD = [] A.sort() B.sort() C.sort() for i in A: for j in B: DD.append(i+j) DD.sort() F = [] for i in DD[min(len(DD)-3010,0):]: for j in C: F.append(i+j) F.sort() for i in range(K): print((F[-1-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())) DD = [] A.sort() B.sort() C.sort() for i in A: for j in B: DD.append(i+j) DD.sort() F = [] for i in DD[max(len(DD)-3010,0):]: for j in C: F.append(i+j) F.sort() for i in range(K): print((F[-1-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) now = [0, 0, 0] que = [[A[0] + B[0] + C[0], 0, 0, 0]] memory = [[A[0] + B[0] + C[0], 0, 0, 0]] ans = [] while len(ans) < k: maxli = max(que, key = lambda x:x[0]) ans.append(maxli[0]) now = maxli[1:] que.remove(maxli) a = A[min(now[0] + 1, x - 1)] b = B[min(now[1] + 1, y - 1)] c = C[min(now[2] + 1, z - 1)] if [a + B[now[1]] + C[now[2]], min(now[0] + 1, x - 1), now[1], now[2]] not in memory: que.append([a + B[now[1]] + C[now[2]], min(now[0] + 1, x - 1), now[1], now[2]]) memory.append([a + B[now[1]] + C[now[2]], min(now[0] + 1, x - 1), now[1], now[2]]) if [A[now[0]] + b + C[now[2]], now[0], min(now[1] + 1, y - 1), now[2]] not in memory: que.append([A[now[0]] + b + C[now[2]], now[0], min(now[1] + 1, y - 1), now[2]]) memory.append([A[now[0]] + b + C[now[2]], now[0], min(now[1] + 1, y - 1), now[2]]) if [A[now[0]] + B[now[1]] + c, now[0], now[1], min(now[2] + 1, z - 1)] not in memory: que.append([A[now[0]] + B[now[1]] + c, now[0], now[1], min(now[2] + 1, z - 1)]) memory.append([A[now[0]] + B[now[1]] + c, now[0], now[1], min(now[2] + 1, z - 1)]) print(*ans, sep = "\n")
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) now = [0, 0, 0] que = [[A[0] + B[0] + C[0], 0, 0, 0]] memory = [[0, 0, 0]] ans = [] while len(ans) < k: maxli = max(que, key = lambda x:x[0]) ans.append(maxli[0]) now = maxli[1:] que.remove(maxli) a = A[min(now[0] + 1, x - 1)] b = B[min(now[1] + 1, y - 1)] c = C[min(now[2] + 1, z - 1)] if [min(now[0] + 1, x - 1), now[1], now[2]] not in memory: que.append([a + B[now[1]] + C[now[2]], min(now[0] + 1, x - 1), now[1], now[2]]) memory.append([min(now[0] + 1, x - 1), now[1], now[2]]) if [now[0], min(now[1] + 1, y - 1), now[2]] not in memory: que.append([A[now[0]] + b + C[now[2]], now[0], min(now[1] + 1, y - 1), now[2]]) memory.append([now[0], min(now[1] + 1, y - 1), now[2]]) if [now[0], now[1], min(now[2] + 1, z - 1)] not in memory: que.append([A[now[0]] + B[now[1]] + c, now[0], now[1], min(now[2] + 1, z - 1)]) memory.append([now[0], now[1], min(now[2] + 1, z - 1)]) print(*ans, sep = "\n")
p03078
X, Y, Z, K = list(map(int, input().split())) A_list = list(map(int, input().split())) B_list = list(map(int, input().split())) C_list = list(map(int, input().split())) import itertools val_list = [] a_max = min(len(A_list), K) b_max = min(len(B_list), K) c_max = min(len(C_list), K) A_list = sorted(A_list, reverse=True) B_list = sorted(B_list, reverse=True) C_list = sorted(C_list, reverse=True) for a, b, c in itertools.product(A_list[:a_max], B_list[:b_max], C_list[:c_max]): val_list.append(a + b + c) val_list = sorted(val_list, reverse=True) for i in range(K): print((val_list[i]))
X, Y, Z, K = list(map(int, input().split())) A_list = list(map(int, input().split())) B_list = list(map(int, input().split())) C_list = list(map(int, input().split())) import itertools val_list = [] A_list = sorted(A_list, reverse=True) B_list = sorted(B_list, reverse=True) C_list = sorted(C_list, reverse=True) #print(A_list) #print(B_list) #print(C_list) for a, b, c in itertools.product(list(range(len(A_list))), list(range(len(B_list))), list(range(len(C_list)))): if (a+1) * (b+1) * (c+1) > K: continue val_list.append(A_list[a] + B_list[b] + C_list[c]) val_list = sorted(val_list, reverse=True) for i in range(K): print((val_list[i]))
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()] A.sort(reverse=True) B.sort(reverse=True) C.sort(reverse=True) x = 0 y = 0 z = 0 cakes = [] for x, a in enumerate(A): for y, b in enumerate(B): for z, c in enumerate(C): if (x+1)*(y+1)*(z+1) > k: break cakes.append(a+b+c) cakes.sort(reverse=True) for cake in cakes[:k]: print(cake)
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) x = 0 y = 0 z = 0 cakes = [] for x, a in enumerate(A): if x+1 > k: break for y, b in enumerate(B): if (x+1)*(y+1) > k: break for z, c in enumerate(C): if (x+1)*(y+1)*(z+1) > k: break cakes.append(a+b+c) cakes.sort(reverse=True) for cake in cakes[:k]: print(cake)
p03078
x,y,z,N =(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()] sa=sorted(a,reverse=True) sb=sorted(b,reverse=True) sc=sorted(c,reverse=True) l=[]#端点情報 n=0 i=0 j=0 k=0 while n<N: print((sa[i]+sb[j]+sc[k])) l.append([i,j,k]) maxl=0 maxijk=[len(sa)-1,len(sb)-1,len(sc)-1] for w in l: if w[0]<len(sa)-1: if not ([w[0]+1,w[1],w[2]] in l): if maxl<=sa[w[0]+1]+sb[w[1]]+sc[w[2]]: maxl=sa[w[0]+1]+sb[w[1]]+sc[w[2]] maxijk=[w[0]+1,w[1],w[2]] if w[1]<len(sb)-1: if not([w[0],w[1]+1,w[2]] in l): if maxl<=sa[w[0]]+sb[w[1]+1]+sc[w[2]]: maxl=sa[w[0]]+sb[w[1]+1]+sc[w[2]] maxijk=[w[0],w[1]+1,w[2]] if w[2]<len(sc)-1: if not([w[0],w[1],w[2]+1] in l): if maxl<=sa[w[0]]+sb[w[1]]+sc[w[2]+1]: maxl=sa[w[0]]+sb[w[1]]+sc[w[2]+1] maxijk=[w[0],w[1],w[2]+1] i=maxijk[0] j=maxijk[1] k=maxijk[2] n+=1
#解答を見た後 x,y,z,N =(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()] sa=sorted(a,reverse=True) sb=sorted(b,reverse=True) sc=sorted(c,reverse=True) answer=[] for i in range(len(sa)): for j in range(len(sb)): if (i+1)*(j+1)>N:break for k in range(len(sb)): if (i+1)*(j+1)*(k+1)>N:break answer.append(sa[i]+sb[j]+sc[k]) answer=sorted(answer,reverse=True) for i in range(0,N): print((answer[i]))
p03078
import heapq import collections 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) heap = [] heapq.heapify(heap) heapq.heappush(heap,(-(A[0]+B[0]+C[0]),0,0,0)) dictionary = collections.defaultdict(bool) dictionary[(0,0,0)] = True i = 0 while i<k: M = heapq.heappop(heap) print((-M[0])) i += 1 if not dictionary[(M[1]+1,M[2],M[3])] and M[1]+1<x: heapq.heappush(heap,(-(A[M[1]+1]+B[M[2]]+C[M[3]]),M[1]+1,M[2],M[3])) dictionary[(M[1]+1,M[2],M[3])] = True if not dictionary[(M[1],M[2]+1,M[3])] and M[2]+1<y: heapq.heappush(heap,(-(A[M[1]]+B[M[2]+1]+C[M[3]]),M[1],M[2]+1,M[3])) dictionary[(M[1],M[2]+1,M[3])] = True if not dictionary[(M[1],M[2],M[3]+1)] and M[3]+1<z: heapq.heappush(heap,(-(A[M[1]]+B[M[2]]+C[M[3]+1]),M[1],M[2],M[3]+1)) dictionary[(M[1],M[2],M[3]+1)] = True
from heapq import heappop, heappush, heapify 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) heap = list() used = set() res = list() heappush(heap, (-(A[0] + B[0] + C[0]), 0, 0, 0)) used.add((0, 0, 0)) for _ in range(K): v, i, j, k = heappop(heap) res.append(-v) if i + 1 < X and (i + 1, j, k) not in used: used.add((i + 1, j, k)) heappush(heap, (-(A[i + 1] + B[j] + C[k]), i + 1, j, k)) if j + 1 < Y and (i, j + 1, k) not in used: used.add((i, j + 1, k)) heappush(heap, (-(A[i] + B[j + 1] + C[k]), i, j + 1, k)) if k + 1 < Z and (i, j, k + 1) not in used: used.add((i, j, k + 1)) heappush(heap, (-(A[i] + B[j] + C[k + 1]), i, j, k + 1)) print(('\n'.join(map(str, res))))
p03078
def dfs(count, ans, ll): if count == 2: for cc in c: cccc = ans + cc if cccc is not None: ll.append(cccc) if count == 1: for bb in b: bbbb = dfs(count+1, ans+bb, ll) if bbbb is not None: ll.append(bbbb) if count == 0: for aa in a: aaaa = dfs(count+1, ans+aa, ll) if aaaa is not None: ll.append(aaaa) return ll 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()] aaa = [] ans = dfs(0, 0, aaa) ans.sort() ans = list(reversed(ans)) for i in range(k): print((ans[i]))
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 = list(reversed(sorted(a))) b = list(reversed(sorted(b))) c = list(reversed(sorted(c))) ans = [] for i in range(x): for j in range(y): for l in range(z): if i * j * l <= k: ans.append(a[i] + b[j] + c[l]) else: break ans = list(reversed(sorted(ans))) 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.sort(reverse=True) B.sort(reverse=True) C.sort(reverse=True) import heapq nums=[[-(A[0]+B[0]+C[0]), 0, 0, 0]] heapq.heapify(nums) sumi=[[[0]*Z for __ in range(Y)] for _ in range(X)] for _ in range(K): out, a, b, c=heapq.heappop(nums) print((-out)) if a<X-1 and sumi[a+1][b][c]==0: heapq.heappush(nums, [-(A[a+1]+B[b]+C[c]), a+1, b, c]) sumi[a+1][b][c]=1 if b<Y-1 and sumi[a][b+1][c]==0: heapq.heappush(nums, [-(A[a]+B[b+1]+C[c]), a, b+1, c]) sumi[a][b+1][c]=1 if c<Z-1 and sumi[a][b][c+1]==0: heapq.heappush(nums, [-(A[a]+B[b]+C[c+1]), a, b, c+1]) sumi[a][b][c+1]=1
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) import heapq nums=[[-(A[0]+B[0]+C[0]), 0, 0, 0]] heapq.heapify(nums) sumi=[[0, 0, 0]] for _ in range(K): out, a, b, c=heapq.heappop(nums) print((-out)) if a<X-1 and not([a+1, b, c] in sumi): heapq.heappush(nums, [-(A[a+1]+B[b]+C[c]), a+1, b, c]) sumi.append([a+1, b, c]) if b<Y-1 and not([a, b+1, c] in sumi): heapq.heappush(nums, [-(A[a]+B[b+1]+C[c]), a, b+1, c]) sumi.append([a, b+1, c]) if c<Z-1 and not([a, b, c+1] in sumi): heapq.heappush(nums, [-(A[a]+B[b]+C[c+1]), a, b, c+1]) sumi.append([a, b, c+1])
p03078
# coding: utf-8 #解法1 ABのK番まで + CのK番まで 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(min(K,X)): for j in range(min(K,Y)): AB.append(A[i]+B[j]) AB.sort(reverse=True) C.sort(reverse=True) ABC=[] for i in range(min(K,X*Y)): for j in range(min(K,Z)): ABC.append(AB[i]+C[j]) ABC.sort(reverse=True) for i in range(K): print((ABC[i]))
# coding: utf-8 #解法1 ABのK番まで + CのK番まで 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): for k in range(Z): if (i+1)*(j+1)*(k+1)>K: break else: ABC.append(A[i]+B[j]+C[k]) if (i+1)*(j+1)>K: break if i+1>K: break ABC.sort(reverse=True) for i in range(K): print((ABC[i]))
p03078
# coding: utf-8 #解法1 ABのK番まで + CのK番まで 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): for k in range(Z): if (i+1)*(j+1)*(k+1)>K: break else: ABC.append(A[i]+B[j]+C[k]) if (i+1)*(j+1)>K: break if i+1>K: break ABC.sort(reverse=True) for i in range(K): print((ABC[i]))
# coding: utf-8 #解法2 abc<=Kのみのリスト 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): for k in range(Z): if (i+1)*(j+1)*(k+1)>K: break else: ABC.append(A[i]+B[j]+C[k]) if (i+1)*(j+1)>K: break if i+1>K: break ABC.sort(reverse=True) for i in range(K): print((ABC[i]))
p03078
import sys input = sys.stdin.readline def main(): 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()] ans = [] for a in A: for b in B: for c in C: ans.append(a + b + c) ans_s = sorted(ans, reverse=True) for i in range(K): print((ans_s[i])) if __name__ == '__main__': main()
import sys input = sys.stdin.readline def main(): 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()] ans = [] for a in A: for b in B: ans.append(a + b) ans_s = sorted(ans, reverse=True) ans2 = [] for a in ans_s[:3000]: for c in C: ans2.append(a + c) ans2_s = sorted(ans2, reverse=True) for i in range(K): print((ans2_s[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() B.sort() C.sort() A = A[::-1] B = B[::-1] C = C[::-1] anslist = [] for i in range(len(A)): if i > k: break for j in range(len(B)): if i * j > k: break for l in range(len(C)): if (i + 1) * (j + 1) * (l + 1) > k: break anslist.append(A[i] + B[j] + C[l]) anslist.sort() anslist = anslist[::-1] 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() B.sort() C.sort() A = A[::-1] B = B[::-1] C = C[::-1] anslist = [] 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 l in range(len(C)): if (i + 1) * (j + 1) * (l + 1) > k: break anslist.append(A[i] + B[j] + C[l]) anslist.sort() anslist = anslist[::-1] for i in range(k): print((anslist[i]))
p03078
# coding: utf-8 import sys 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())) bimi = [] for a in range(X): for b in range(Y): bimi.append(A[a] + B[b]) bimi.sort(reverse=True) ans = [] for x in range(min(K, len(bimi))): for c in range(Z): ans.append(bimi[x] + C[c]) ans.sort(reverse=True) for i in range(K): print((ans[i]))
# coding: utf-8 import sys input = sys.stdin.readline 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) bimi = [] for a in range(X): for b in range(Y): if (a + 1) * (b + 1) > K: break for c in range(Z): if (a + 1) * (b + 1) * (c + 1) > K: break bimi.append(A[a] + B[b] + C[c]) bimi.sort(reverse=True) for i in range(K): print((bimi[i]))
p03078
x,y,z,n = 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) d = [] for i,i1 in enumerate(a): for j,j1 in enumerate(b): for k,k1 in enumerate(c): if (i+1) * (j+1) * (k+1) <= n: d.append(i1 + j1 + k1) d.sort(reverse = True) for i in d[:n]: print(i)
x,y,z,n = 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) d = [] for i,i1 in enumerate(a): for j,j1 in enumerate(b): if (i+1)*(j+1) <= n: for k,k1 in enumerate(c): if (i+1) * (j+1) * (k+1) <= n: d.append(i1 + j1 + k1) else: break else: break d.sort(reverse = True) for i in d[:n]: print(i)
p03078
def resolve(): 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 = [] 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 = sorted(ABC, reverse=True) [print(ABC[i]) for i in range(K)] if '__main__' == __name__: resolve()
def resolve(): 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) ABC = [] for i in range(X): for j in range(Y): for k in range(Z): if ((i+1)*(j+1)*(k+1) > K): break ABC.append(A[i]+B[j]+C[k]) ABC = sorted(ABC, reverse=True) [print(ABC[i]) for i in range(K)] if '__main__' == __name__: resolve()
p03078
import itertools import heapq import copy def inv(l): return list([x*-1 for x in l]) def solve(A,B,C, K): A,B,C = inv(A), inv(B), inv(C) A = sorted(A) B = sorted(B) C = sorted(C) ind = set([(0,0,0)]) h = [(A[0]+ B[0]+ C[0], (0,0,0))] res = [] for _ in range(K): h2 = copy.copy(h) for (val, (i,j,k)) in h2: if i+1 < len(A) and (i+1,j,k) not in ind: heapq.heappush(h, (A[i+1]+B[j]+C[k], (i+1, j, k))) ind |= set([(i+1,j,k)]) if j+1 < len(B) and (i,j+1, k) not in ind: heapq.heappush(h, (A[i]+B[j+1]+C[k], (i, j+1, k))) ind |= set([(i,j+1,k)]) if k+1 < len(C) and (i,j, k+1) not in ind: heapq.heappush(h, (A[i]+B[j]+C[k+1], (i, j, k+1))) ind |= set([(i,j,k+1)]) res += [heapq.heappop(h)] for r in res: print((r[0]*-1)) la,lb,lc,K = list(map(int, input().split(' '))) A = list(map(int, input().split(' '))) B = list(map(int, input().split(' '))) C = list(map(int, input().split(' '))) solve(A,B,C,K)
import itertools import heapq import copy def inv(l): return list([x*-1 for x in l]) def solve(A,B,C, K): A,B,C = inv(A), inv(B), inv(C) A = sorted(A) B = sorted(B) C = sorted(C) ind = set([(0,0,0)]) h = [(A[0]+ B[0]+ C[0], (0,0,0))] res = [] for _ in range(K): h2 = copy.copy(h) val, (i,j,k) = heapq.heappop(h) res += [-val] if i+1 < len(A) and (i+1,j,k) not in ind: heapq.heappush(h, (A[i+1]+B[j]+C[k], (i+1, j, k))) ind |= set([(i+1,j,k)]) if j+1 < len(B) and (i,j+1, k) not in ind: heapq.heappush(h, (A[i]+B[j+1]+C[k], (i, j+1, k))) ind |= set([(i,j+1,k)]) if k+1 < len(C) and (i,j, k+1) not in ind: heapq.heappush(h, (A[i]+B[j]+C[k+1], (i, j, k+1))) ind |= set([(i,j,k+1)]) for r in res: print(r) la,lb,lc,K = list(map(int, input().split(' '))) A = list(map(int, input().split(' '))) B = list(map(int, input().split(' '))) C = list(map(int, input().split(' '))) solve(A,B,C,K)
p03078
# TODO D - Cake 123 # https://atcoder.jp/contests/abc123/tasks/abc123_d X, Y, Z, K = list(map(int, input().split())) A = [int(x) for x in input().split()] B = [int(y) for y in input().split()] C = [int(z) for z in input().split()] AB = sorted([a+b for a in A for b in B], reverse=True) ABC = sorted([ab + c for ab in AB[:K] for c in C], reverse=True) for i in ABC[:K]: print('{}'.format(i))
#abc123d x,y,z,k=list(map(int,input().split())) a=sorted(map(int,input().split()),reverse=True) b=sorted(map(int,input().split()),reverse=True) c=sorted(map(int,input().split()),reverse=True) ab=sorted([i+j for i in a for j in b],reverse=True) res=sorted([ij+l for ij in ab[:k] for l in c],reverse=True) for i in res[:k]: print(i)
p03078
X, Y, Z, K = [int(_) for _ in input().split()] A = [int(_) for _ in input().split()] B = [int(_) for _ in input().split()] C = [int(_) for _ in input().split()] A = sorted(A) B = sorted(B) C = sorted(C) maxn = A[0] * B[0] * C[0] from heapq import * h = [] heappush(h, (-A[-1] - B[-1] - C[-1], len(A) - 1, len(B) - 1, len(C) - 1)) used = {} for i in range(min(K, X * Y * Z)): v, ix, iy, iz = heappop(h) print((-v)) def push(x, y, z): if x >= 0 and y >= 0 and z >= 0 and (x, y, z) not in used: heappush(h, (-A[x] - B[y] - C[z], x, y, z)) used[x, y, z] = 1 push(ix - 1, iy, iz) push(ix, iy - 1, iz) push(ix, iy, iz - 1)
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) # Priority QueueとしてHeapを使う # Pythonのheapqは小さい順に取り出すので、-1を掛けて負数としてpushしていく # (-Ai-Bj-Ck, i, j, k) # 取り出したi, j, kについて、(i+1, j, k), (i, j+1, k), (i, j, k+1)に対応するタプルをpushする # ただし、すでにpushした値は入れないようにする import heapq def make(i, j, k): return (-A[i]-B[j]-C[k], i, j, k) used = set() l = [] heapq.heappush(l, make(0, 0, 0)) used.add((0, 0, 0)) for cnt in range(K): V, i, j, k = heapq.heappop(l) if i < X - 1 and (i+1, j, k) not in used: heapq.heappush(l, make(i+1, j, k)) used.add((i+1, j, k)) if j < Y - 1 and (i, j+1, k) not in used: heapq.heappush(l, make(i, j+1, k)) used.add((i, j+1, k)) if k < Z - 1 and (i, j, k+1) not in used: heapq.heappush(l, make(i, j, k+1)) used.add((i, j, k+1)) print((-V))
p03078
import sys sys.setrecursionlimit(10**7) def I(): return int(sys.stdin.readline().rstrip()) def MI(): return map(int,sys.stdin.readline().rstrip().split()) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) #空白あり def LI2(): return list(map(int,sys.stdin.readline().rstrip())) #空白なし def S(): return sys.stdin.readline().rstrip() def LS(): return list(sys.stdin.readline().rstrip().split()) #空白あり def LS2(): return list(sys.stdin.readline().rstrip()) #空白なし X,Y,Z,K = MI() A,B,C = LI(),LI(),LI() A.sort(reverse=True) B.sort(reverse=True) C.sort(reverse=True) ANS = [] for i in range(X): if i >= K: break a = A[i] for j in range(Y): if i*j >= K: break b = B[j] for k in range(Z): if i*j*k >= K: break c = C[k] ANS.append(a+b+c) ANS.sort(reverse=True) print(*ANS[:K],sep='\n')
import sys def MI(): return map(int,sys.stdin.readline().rstrip().split()) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) #空白あり X,Y,Z,K = MI() A,B,C = LI(),LI(),LI() A.sort(reverse=True) B.sort(reverse=True) C.sort(reverse=True) ANS = [] for i in range(X): if i >= K: break a = A[i] for j in range(Y): if i*j >= K: break b = B[j] for k in range(Z): if i*j*k >= K: break c = C[k] ANS.append(a+b+c) ANS.sort(reverse=True) print(*ANS[:K],sep='\n')
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())) x = [] for a in A: for b in B: for c in C: x.append(a + b + c) x.sort(reverse=True) for i in range(K): print((x[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 range(x): for j in range(y): ab.append(a[i] + b[j]) ab.sort(reverse = True) abc = [] for i in range(min(3000, len(ab))): for j in range(z): abc.append(ab[i] + c[j]) 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 = [] for i in range(x): for j in range(y): ab.append(a[i] + b[j]) ab.sort(reverse = True) abc = [] for i in range(min(k,len(ab))): for j in range(z): 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())) 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 l in range(z): if (i + 1) * (j + 1) * (l + 1 ) > k: break abc.append(a[i] + b[j] + c[l]) abc.sort(reverse = True) for i in range(k): print((abc[i]))
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()] d=[] ans=[] for i in a: for j in b: d.append(i+j) for i in c: for j in d: ans.append(i+j) ans.sort(reverse=True) for i in range(k): print((ans[i]))
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) if k>x: a=a[:k] if k>y: b=b[:k] if k>z: c=c[:k] d=[] ans=[] for i in a: for j in b: d.append(i+j) d.sort(reverse=True) if len(d)>k: d=d[:k] for i in c: for j in d: ans.append(i+j) ans.sort(reverse=True) for i in range(k): print((ans[i]))
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()] a.sort(reverse=True) b.sort(reverse=True) c.sort(reverse=True) if k<x: a=a[:k] if k<y: b=b[:k] if k<z: c=c[:k] d=[] ans=[] for i in a: for j in b: d.append(i+j) d.sort(reverse=True) if len(d)<k: d=d[:k] for i in c: for j in d: ans.append(i+j) ans.sort(reverse=True) for i in range(k): print((ans[i]))
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) if k<x: a=a[:k] if k<y: b=b[:k] if k<z: c=c[:k] d=[] ans=[] for i in a: for j in b: d.append(i+j) d.sort(reverse=True) if k<len(d): d=d[:k] for i in c: for j in d: ans.append(i+j) ans.sort(reverse=True) for i in range(k): print((ans[i]))
p03078
def main(): import heapq x, y, z, k, *abc = map(int, open(0).read().split()) a = abc[:x] b = abc[x:x + y] c = abc[x + y:] s = set() a.sort(reverse=True) b.sort(reverse=True) c.sort(reverse=True) h = [(-(a[0] + b[0] + c[0]), 0, 0, 0)] heapq.heapify(h) ans = [] for _ in range(k): p, i, j, k = heapq.heappop(h) ans.append(-p) for p, q, r in [(1, 0, 0), (0, 1, 0), (0, 0, 1)]: if i + p < x and j + q < y and k + r < z: if (i + p, j + q, k + r) not in s: s.add((i + p, j + q, k + r)) v = - (a[i + p] + b[j + q] + c[k + r]) heapq.heappush(h, (v, i + p, j + q, k + r)) print(*ans, sep='\n') if __name__ == '__main__': main()
def main(): import heapq x, y, z, k, *abc = list(map(int, open(0).read().split())) a = sorted(abc[:x], reverse=True) b = sorted(abc[x:x + y], reverse=True) c = sorted(abc[x + y:], reverse=True) s = set() h = [(-(a[0] + b[0] + c[0]), 0, 0, 0)] heapq.heapify(h) num = [] for _ in range(k): p, i, j, k = heapq.heappop(h) num.append(-p) for p, q, r in [(1, 0, 0), (0, 1, 0), (0, 0, 1)]: if i + p < x and j + q < y and k + r < z: if (i + p, j + q, k + r) not in s: s.add((i + p, j + q, k + r)) v = - (a[i + p] + b[j + q] + c[k + r]) heapq.heappush(h, (v, i + p, j + q, k + r)) ans = '\n'.join(map(str, num)) print(ans) if __name__ == '__main__': main()
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())) a.sort(reverse = True) b.sort(reverse = True) c.sort(reverse = True) n = [] heapq.heapify(n) heapq.heappush(n, (-(a[0]+b[0] + c[0]), 0,0,0)) for i in range(K): (m, j, k, l) = heapq.heappop(n) print((-m)) if j + 1 <=x-1: s = (-(a[j+1]+b[k]+c[l]), j+1, k, l) if s not in n: heapq.heappush(n ,s) if k + 1 <=y-1: s = (-(a[j]+b[k+1]+c[l]), j, k+1, l) if s not in n: heapq.heappush(n ,s) if l+ 1 <=z-1: s = (-(a[j]+b[k]+c[l+1]), j, k, l+1) if s not in n: heapq.heappush(n ,s)
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) ans = [(-(a[0]+b[0]+c[0]), 0, 0, 0)] for i in range(K): m, j, k, h = heapq.heappop(ans) print((-m)) if j+1 <= X-1: s =(-(a[j+1]+b[k]+c[h]), j+1, k, h) if s not in ans: heapq.heappush(ans, s) if k+1 <= Y-1: s =(-(a[j]+b[k+1]+c[h]), j , k+1, h) if s not in ans: heapq.heappush(ans, s) if h+1 <= Z-1: s =(-(a[j]+b[k]+c[h+1]), j , k, h+1) if s not in ans: heapq.heappush(ans, 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())) ans = [] for aa in a: for bb in b: for cc in c: ans.append(aa+bb+cc) for ansi in sorted(ans)[::-1][:k]: print(ansi)
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 aa in a: for bb in b: ab.append(aa+bb) ab = sorted(ab)[::-1][:k] ans = [] for aabb in ab: for cc in c: ans.append(aabb+cc) for ansi in sorted(ans)[::-1][:k]: print(ansi)
p03078
x, y, z, k = list(map(int, input().split())) a_array = sorted([int(x) for x in input().split()], reverse=True) b_array = sorted([int(x) for x in input().split()], reverse=True) c_array = sorted([int(x) for x in input().split()], reverse=True) def solver1(): ab_array = [x + y for x in a_array for y in b_array] abc_array = sorted([ab + c for ab in ab_array for c in c_array], reverse=True) for abc in abc_array[:k]: print(abc) solver1()
x, y, z, k = list(map(int, input().split())) a_array = sorted([int(x) for x in input().split()], reverse=True) b_array = sorted([int(x) for x in input().split()], reverse=True) c_array = sorted([int(x) for x in input().split()], reverse=True) def solver1(): ab_array = sorted([x + y for x in a_array for y in b_array], reverse=True)[:3000] abc_array = sorted([ab + c for ab in ab_array for c in c_array], reverse=True) for abc in abc_array[:k]: print(abc) solver1()
p03078
# D - Cake 123 import heapq import itertools x, y, z, k = list(map(int, input().split())) A = list(int(a) for a in input().split()) B = list(int(b) for b in input().split()) C = list(int(c) for c in input().split()) hq = [] for i, j in itertools.product(A, B): heapq.heappush(hq, (i+j)*-1) AB = [] while len(hq)>0 and len(AB)<=k: AB.append(heapq.heappop(hq)*-1) hq = [] for i, j in itertools.product(AB, C): heapq.heappush(hq, (i+j)*-1) for _ in range(k): print((heapq.heappop(hq)*-1))
# D - Cake 123 import heapq import itertools x, y, z, k = list(map(int, input().split())) A = list(int(a) for a in input().split()) B = list(int(b) for b in input().split()) C = list(int(c) for c in input().split()) A.sort(reverse=True) B.sort(reverse=True) C.sort(reverse=True) hq = [] for i in range(x): for j in range(y): for l in range(z): if (i+1)*(j+1)*(l+1)<=k: heapq.heappush(hq, (A[i]+B[j]+C[l])*-1) else: break ''' hq = [] for i, j in itertools.product(A, B): heapq.heappush(hq, (i+j)*-1) AB = [] while len(hq)>0 and len(AB)<=k: AB.append(heapq.heappop(hq)*-1) hq = [] for i, j in itertools.product(AB, C): heapq.heappush(hq, (i+j)*-1) ''' for _ in range(k): print((heapq.heappop(hq)*-1))
p03078
# D - Cake 123 import heapq import itertools from collections import defaultdict x, y, z, k = list(map(int, input().split())) A = list(int(a) for a in input().split()) B = list(int(b) for b in input().split()) C = list(int(c) for c in input().split()) A.sort(reverse=True) B.sort(reverse=True) C.sort(reverse=True) hq = [] hqAns = [] d = defaultdict(int) heapq.heappush(hq, ((A[0]+B[0]+C[0])*-1,(0,0,0))) d[(0,0,0)] = 1 while len(hqAns)<k : val, key = heapq.heappop(hq) heapq.heappush(hqAns, val) if d[(key[0]+1, key[1], key[2])]==0 and key[0]+1 < x: heapq.heappush(hq, ((A[key[0]+1]+B[key[1]]+C[key[2]])*-1, ((key[0]+1, key[1], key[2])))) d[(key[0]+1, key[1], key[2])] = 1 if d[(key[0], key[1]+1, key[2])]==0 and key[1]+1 < y: heapq.heappush(hq, ((A[key[0]]+B[key[1]+1]+C[key[2]])*-1, ((key[0], key[1]+1, key[2])))) d[(key[0], key[1]+1, key[2])] = 1 if d[(key[0], key[1], key[2]+1)]==0 and key[2]+1 < z: heapq.heappush(hq, ((A[key[0]]+B[key[1]]+C[key[2]+1])*-1, ((key[0], key[1], key[2]+1)))) d[(key[0], key[1], key[2]+1)] = 1 for i in range(k): print((heapq.heappop(hqAns)*-1)) ''' # ans.2 # A.sort(reverse=True) B.sort(reverse=True) C.sort(reverse=True) hq = [] for i in range(x): for j in range(y): for l in range(z): if (i+1)*(j+1)*(l+1)<=k: heapq.heappush(hq, (A[i]+B[j]+C[l])*-1) else: break for _ in range(k): print(heapq.heappop(hq)*-1) ''' ''' # ans.1 # hq = [] for i, j in itertools.product(A, B): heapq.heappush(hq, (i+j)*-1) AB = [] while len(hq)>0 and len(AB)<=k: AB.append(heapq.heappop(hq)*-1) hq = [] for i, j in itertools.product(AB, C): heapq.heappush(hq, (i+j)*-1) for _ in range(k): print(heapq.heappop(hq)*-1) '''
# D - Cake 123 import heapq import itertools from collections import defaultdict x, y, z, k = list(map(int, input().split())) A = list(int(a) for a in input().split()) B = list(int(b) for b in input().split()) C = list(int(c) for c in input().split()) A.sort(reverse=True) B.sort(reverse=True) C.sort(reverse=True) hq = [] hqAns = [] d = defaultdict(int) heapq.heappush(hq, ((A[0]+B[0]+C[0])*-1, 0, 0, 0)) d[(0,0,0)] = 1 while len(hqAns)<k : val, l, m, n = heapq.heappop(hq) heapq.heappush(hqAns, val) if d[(l+1, m, n)]==0 and l+1 < x: heapq.heappush(hq, ((A[l+1]+B[m]+C[n])*-1, l+1, m, n)) d[(l+1, m, n)] = 1 if d[(l, m+1, n)]==0 and m+1 < y: heapq.heappush(hq, ((A[l]+B[m+1]+C[n])*-1, l, m+1, n)) d[(l, m+1, n)] = 1 if d[(l, m, n+1)]==0 and n+1 < z: heapq.heappush(hq, ((A[l]+B[m]+C[n+1])*-1, l, m, n+1)) d[(l, m, n+1)] = 1 for i in range(k): print((heapq.heappop(hqAns)*-1)) ''' # ans.2 # A.sort(reverse=True) B.sort(reverse=True) C.sort(reverse=True) hq = [] for i in range(x): for j in range(y): for l in range(z): if (i+1)*(j+1)*(l+1)<=k: heapq.heappush(hq, (A[i]+B[j]+C[l])*-1) else: break for _ in range(k): print(heapq.heappop(hq)*-1) ''' ''' # ans.1 # hq = [] for i, j in itertools.product(A, B): heapq.heappush(hq, (i+j)*-1) AB = [] while len(hq)>0 and len(AB)<=k: AB.append(heapq.heappop(hq)*-1) hq = [] for i, j in itertools.product(AB, C): heapq.heappush(hq, (i+j)*-1) for _ in range(k): print(heapq.heappop(hq)*-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())) A.sort(reverse= True) B.sort(reverse= True) C.sort(reverse= True) LIS = [] for i in range(X): for j in range(Y): for k in range(min((3000//(i+1)*(j+1)),Z)): SUM = A[i] + B[j] + C[k] LIS.append(SUM) LIS.sort(reverse = True) for i in range(K): print((LIS[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) LIS = [] for i in range(X): INTB = 3000//(i+1) for j in range(min(INTB+1,Y)): INT = 3000//((i+1)*(j+1)) for k in range(min(INT+1,Z)): SUM = A[i] + B[j] + C[k] LIS.append(SUM) LIS.sort(reverse = True) for i in range(K): print((LIS[i]))
p03078
def int_raw(): return int(eval(input())) def ss_raw(): return input().split() def ints_raw(): return list(map(int,ss_raw())) X,Y,Z,K = ints_raw() 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) def main(): D = [] for a in A: for b in B: D.append(a+b) D.sort(reverse=True) D = D[:K+1] E =[] for d in D: for c in C: E.append(d+c) E.sort(reverse=True) for e in range(K): print((E[e])) main()
def int_raw(): return int(eval(input())) def ss_raw(): return input().split() def ints_raw(): return list(map(int,ss_raw())) X,Y,Z,K = ints_raw() 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) def main(): D = [a+b for a in A for b in B] D.sort(reverse=True) D = D[:K+1] E =[d+c for d in D for c in C] E.sort(reverse=True) for e in range(K): print((E[e])) 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())) #入力受け取り AA = [] BB = [] CC = [] for k in range(min(X, K)): maxA = max(A) A.remove(maxA) AA.append(maxA) for k in range(min(Y, K)): maxB = max(B) B.remove(max(B)) BB.append(maxB) for k in range(min(Z, K)): maxC = max(C) C.remove(maxC) CC.append(maxC) #list X から X に大きい順にポイントを格納。 indexlist = [] for k in range(min(X, K)): for l in range(min(Y, K)): for m in range(min(Z, K)): indexlist.append([k, l, m]) #インデックスを参照することで大きい順にポイントの組を取得できるような「リストのリスト」を作成 dictionary = {} for P in indexlist: p = AA[P[0]] + BB[P[1]] + CC[P[2]] dictionary.update({str(P[0]) +" , " + str(P[1]) +" , " + str(P[2]): p}) #indexlist 引数の組を取り出し、対応するポイントを足し算して辞書に格納 Ans = list(dictionary.values()) for k in range(K): print((max(Ans))) Ans.remove(max(Ans))
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())) #入力受け取り AA = [] BB = [] CC = [] for k in range(min(X, K)): maxA = max(A) A.remove(maxA) AA.append(maxA) for k in range(min(Y, K)): maxB = max(B) B.remove(maxB) BB.append(maxB) for k in range(min(Z, K)): maxC = max(C) C.remove(maxC) CC.append(maxC) #list X から X に大きい順にポイントを格納。 indexlist = [] for k in range(min(X, K)): for l in range(min(Y, K)): for m in range(min(Z, K)): if k*l*m <= K: indexlist.append([k, l, m]) #インデックスを参照することで大きい順にポイントの組を取得できるような「リストのリスト」を作成 dictionary = {} for P in indexlist: p = AA[P[0]] + BB[P[1]] + CC[P[2]] dictionary.update({str(P[0]) +" , " + str(P[1]) +" , " + str(P[2]): p}) #indexlist 引数の組を取り出し、対応するポイントを足し算して辞書に格納 Ans = list(dictionary.values()) for k in range(K): print((max(Ans))) Ans.remove(max(Ans))
p03078
# PDFで解法が4つも書いてある。これはその最初の解法 x,y,z,k = list(map(int, input().split() )) aa = list(map(int, input().split() )) bb = list(map(int, input().split() )) cc = list(map(int, input().split() )) aa.sort(reverse = True) bb.sort(reverse = True) cc.sort(reverse = True) # 降順=大きい方から順 ab = [] for i in aa: for j in bb: ab.append(i + j) # ab = [i + j for i in aa for j in bb] # appendを使うと遅いので、二重の内包記法を使う # 外側でaaの要素、内側でbbの要素が動いていく。今回はどっちでも良いけど。 ab.sort(reverse = True) max_len = min(k, len(ab)) abc = [] for i in ab[:max_len]: for j in cc: abc.append(i + j) # abc = [i + j for i in ab[:max_len] for j in cc] abc.sort(reverse = True) for i in range(k): print((abc[i]))
# PDFで解法が4つも書いてある。これはその最初の解法 x,y,z,k = list(map(int, input().split() )) aa = list(map(int, input().split() )) bb = list(map(int, input().split() )) cc = list(map(int, input().split() )) aa.sort(reverse = True) bb.sort(reverse = True) cc.sort(reverse = True) # 降順=大きい方から順 ab = [i + j for i in aa for j in bb] # appendを使うと遅いので、二重の内包記法を使う # 外側でaaの要素、内側でbbの要素が動いていく。今回はどっちでも良いけど。 ab.sort(reverse = True) max_len = min(k, len(ab)) abc = [i + j for i in ab[:max_len] for j in cc] abc.sort(reverse = True) for i in range(k): print((abc[i]))
p03078
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readline_s = sys.stdin.readline readlines = sys.stdin.buffer.readlines INF = 10 ** 10 + 7 def main(): X, Y, Z, K = list(map(int, readline().split())) A = sorted(list(map(int, readline().split())), reverse=True) B = sorted(list(map(int, readline().split())), reverse=True) C = sorted(list(map(int, readline().split())), reverse=True) ans = solve1(X, Y, Z, K, A, B, C) print(('\n'.join(map(str, ans)))) def solve1(X, Y, Z, K, A, B, C): AB = [] for i in range(X): for j in range(Y): AB.append(A[i] + B[j]) AB.sort(reverse=True) AB = AB[:min(X * Y, K)] ABC = [] for i in range(len(AB)): for j in range(Z): ABC.append(AB[i] + C[j]) ABC.sort(reverse=True) return ABC[:K] if __name__ == '__main__': main()
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readline_s = sys.stdin.readline readlines = sys.stdin.buffer.readlines INF = 10 ** 10 + 7 def main(): X, Y, Z, K = list(map(int, readline().split())) A = sorted(list(map(int, readline().split())), reverse=True) B = sorted(list(map(int, readline().split())), reverse=True) C = sorted(list(map(int, readline().split())), reverse=True) ans = solve2(X, Y, Z, K, A, B, C) print(('\n'.join(map(str, ans)))) def solve2(X, Y, Z, K, A, B, C): ABC = [] for i in range(X): if (i + 1) > K: break 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 else: ABC.append(A[i] + B[j] + C[k]) return sorted(ABC, reverse=True)[:K] def solve1(X, Y, Z, K, A, B, C): AB = [] for i in range(X): for j in range(Y): AB.append(A[i] + B[j]) AB.sort(reverse=True) AB = AB[:min(X * Y, K)] ABC = [] for i in range(len(AB)): for j in range(Z): ABC.append(AB[i] + C[j]) ABC.sort(reverse=True) return ABC[:K] if __name__ == '__main__': main()
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())) d = [0]*x*y for i in range(x): for j in range(y): d[i*y+j] = a[i]+b[j] d.sort(reverse=True) c.sort(reverse=True) c_len = min(k, z) d_len = min(k, x*y) e = [0]*d_len*c_len for i in range(d_len): for j in range(c_len): e[i*c_len+j] = d[i] + c[j] e.sort(reverse=True) for i in range(k): print((e[i])) if __name__ == '__main__': main()
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())) solve(a, b, c, x, y, z, k) def solve(a, b, c, x, y, z, k): a.sort(reverse=True) b.sort(reverse=True) c.sort(reverse=True) stack = list() for p in range(x): for q in range(y): if (p+1)*(q+1) > k: break for r in range(z): if (p+1)*(q+1)*(r+1) > k: break stack.append(a[p]+b[q]+c[r]) stack.sort(reverse=True) for i in range(k): print((stack[i])) if __name__ == '__main__': main()
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(reverse=True) b.sort(reverse=True) c.sort(reverse=True) al = [[[0 for i in range(z)] for j in range(y)] for jj in range(x)] hq = [] heapq.heappush(hq,(-(a[0]+b[0]+c[0]),0,0,0)) for i in range(k): hqi,ai,bi,ci = heapq.heappop(hq) print((-hqi)) if ai+1 < x and al[ai+1][bi][ci] == 0: heapq.heappush(hq,(-(a[ai+1]+b[bi]+c[ci]),ai+1,bi,ci)) al[ai+1][bi][ci] = -1 if bi+1 < y and al[ai][bi+1][ci] == 0: heapq.heappush(hq,(-(a[ai]+b[bi+1]+c[ci]),ai,bi+1,ci)) al[ai][bi+1][ci] = -1 if ci+1 < z and al[ai][bi][ci+1] == 0: heapq.heappush(hq,(-(a[ai]+b[bi]+c[ci+1]),ai,bi,ci+1)) al[ai][bi][ci+1] = -1
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(reverse=True) b.sort(reverse=True) c.sort(reverse=True) al = [] hq = [] heapq.heappush(hq,(-(a[0]+b[0]+c[0]),0,0,0)) for i in range(k): hqi,ai,bi,ci = heapq.heappop(hq) print((-hqi)) if ai+1 < x and not (ai+1,bi,ci) in al: heapq.heappush(hq,(-(a[ai+1]+b[bi]+c[ci]),ai+1,bi,ci)) al.append((ai+1,bi,ci)) if bi+1 < y and not (ai,bi+1,ci) in al: heapq.heappush(hq,(-(a[ai]+b[bi+1]+c[ci]),ai,bi+1,ci)) al.append((ai,bi+1,ci)) if ci+1 < z and not (ai,bi,ci+1) in al: heapq.heappush(hq,(-(a[ai]+b[bi]+c[ci+1]),ai,bi,ci+1)) al.append((ai,bi,ci+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())) A.sort() B.sort() C.sort() from heapq import heappush,heappop ans=[] data=[(-A[-1]-B[-1]-C[-1],X-1,Y-1,Z-1)] visited=set() while len(ans)<K: now=heappop(data) if (now[1],now[2],now[3]) not in visited: ans.append(-1*now[0]) visited|={(now[1],now[2],now[3])} if now[1]>0: nex=now[0]+A[now[1]]-A[now[1]-1] heappush(data,(nex,now[1]-1,now[2],now[3])) if now[2]>0: nex=now[0]+B[now[2]]-B[now[2]-1] heappush(data,(nex,now[1],now[2]-1,now[3])) if now[3]>0: nex=now[0]+C[now[3]]-C[now[3]-1] heappush(data,(nex,now[1],now[2],now[3]-1)) 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() B.sort() C.sort() from heapq import heappush,heappop ans=[] data=[(-A[-1]-B[-1]-C[-1],X-1,Y-1,Z-1)] visited={(X-1,Y-1,Z-1)} while len(ans)<K: now=heappop(data) ans.append(-1*now[0]) if now[1]>0 and (now[1]-1,now[2],now[3]) not in visited: nex=now[0]+A[now[1]]-A[now[1]-1] heappush(data,(nex,now[1]-1,now[2],now[3])) visited|={(now[1]-1,now[2],now[3])} if now[2]>0 and (now[1],now[2]-1,now[3]) not in visited: nex=now[0]+B[now[2]]-B[now[2]-1] heappush(data,(nex,now[1],now[2]-1,now[3])) visited|={(now[1],now[2]-1,now[3])} if now[3]>0 and (now[1],now[2],now[3]-1) not in visited: nex=now[0]+C[now[3]]-C[now[3]-1] heappush(data,(nex,now[1],now[2],now[3]-1)) visited|={(now[1],now[2],now[3]-1)} 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())) C.sort(reverse=True) C=C[:K] from itertools import product D=sorted([a+b for a,b in product(A,B)],reverse=True) D=D[:K] E=sorted([d+c for d,c in product(D,C)],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) C=C[:K] from itertools import product D=sorted([a+b for a,b in product(A,B)],reverse=True) D=D[:K] E=sorted([d+c for d,c in product(D,C)],reverse=True) E=E[:K] for i in range(K): print((E[i]))
p03078
import sys read = sys.stdin.readline def read_ints(): return list(map(int, read().split())) X, Y, Z, K = read_ints() A = list(map(int,input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) from itertools import product AB = [a + b for a, b in product(A, B)] AB.sort(reverse=True) ABC = [ab + c for ab, c in product(AB[:K], C)] ABC.sort(reverse=True) ABC = ABC[:K] print(*ABC, sep='\n')
# 全探索に終了条件を追加することで計算量を削減させるやり方 import sys read = sys.stdin.readline def read_ints(): return list(map(int, read().split())) X, Y, Z, K = read_ints() A = read_ints() B = read_ints() C = read_ints() A.sort(reverse=True) B.sort(reverse=True) C.sort(reverse=True) ABC = [] for a in range(X): if a + 1 > K: break for b in range(Y): if (a + 1) * (b + 1) > K: break for c in range(Z): # a,b,cはA,B,Cの上から何番目に大きいか if (a + 1) * (b + 1) * (c + 1) > K: break ABC.append(A[a] + B[b] + C[c]) ABC.sort(reverse=True) ABC = ABC[:K] print(*ABC, sep='\n')
p03078
# ヒープに要素を追加、一番でかいのを取り出すという操作を最大3000回やるやり方 # これもなかなか早い # ヒープは追加も要素の取り出しもO(log n)で住むので、 # 計算オーダーはO(K log n)で済む(nはヒープの要素数)らしいが # not in があるのでO(n K log n)では? # pythonのヒープは使い方に癖があるのでこの機会に習得しよう import sys read = sys.stdin.readline def read_ints(): return list(map(int, read().split())) X, Y, Z, K = read_ints() A = read_ints() B = read_ints() C = read_ints() A.sort(reverse=True) B.sort(reverse=True) C.sort(reverse=True) heap = [] # ヒープといっても順序を工夫したただのリスト from queue import PriorityQueue heap = PriorityQueue() heap.put((-(A[0] + B[0] + C[0]), 0, 0, 0)) considerd = set() ans = [] for k_th in range(1, K+1): heap_max, i, j, k = heap.get() # print(heap_max) ans.append(-heap_max) for di, dj, dk in zip([1, 0, 0], [0, 1, 0], [0, 0, 1]): i_new, j_new, k_new = i + di, j + dj, k + dk if i_new >= X or j_new >= Y or k_new >= Z: continue if (i_new, j_new, k_new) in considerd: continue considerd.add((i_new, j_new, k_new)) heap.put((-(A[i_new] + B[j_new] + C[k_new]), i_new, j_new, k_new)) print(*ans, sep='\n')
# ヒープに要素を追加、一番でかいのを取り出すという操作を最大3000回やるやり方 # これもなかなか早い # ヒープは追加も要素の取り出しもO(log n)で住むので、 # 計算オーダーはO(K log n)で済む(nはヒープの要素数)らしいが # not in があるのでO(n K log n)では? # pythonのヒープは使い方に癖があるのでこの機会に習得しよう import sys read = sys.stdin.readline def read_ints(): return list(map(int, read().split())) X, Y, Z, K = read_ints() A = read_ints() B = read_ints() C = read_ints() A.sort(reverse=True) B.sort(reverse=True) C.sort(reverse=True) heap = [] # ヒープといっても順序を工夫したただのリスト from heapq import heapify, heappop, heappush, heappushpop heappush(heap, (-(A[0] + B[0] + C[0]), 0, 0, 0)) ans = [] considerd = set() for k_th in range(1, K+1): heap_max, i, j, k = heappop(heap) # print(heap_max) ans.append(-heap_max) for di, dj, dk in zip([1, 0, 0], [0, 1, 0], [0, 0, 1]): i_new, j_new, k_new = i + di, j + dj, k + dk if i_new >= X or j_new >= Y or k_new >= Z: continue if (i_new, j_new, k_new) in considerd: # ここが計算量がおおい continue considerd.add((i_new, j_new, k_new)) heappush(heap, (-(A[i_new] + B[j_new] + C[k_new]), i_new, j_new, k_new)) # print(heap) print(*ans, sep='\n')
p03078
# ヒープに要素を追加、一番でかいのを取り出すという操作を最大3000回やるやり方 # これもなかなか早い # ヒープは追加も要素の取り出しもO(log n)で住むので、 # 計算オーダーはO(K log n)で済む(nはヒープの要素数)らしいが # not in があるのでO(n K log n)では? # pythonのヒープは使い方に癖があるのでこの機会に習得しよう import sys read = sys.stdin.readline def read_ints(): return list(map(int, read().split())) X, Y, Z, K = read_ints() A = read_ints() B = read_ints() C = read_ints() A.sort(reverse=True) B.sort(reverse=True) C.sort(reverse=True) from heapq import heapify, heappop, heappush, heappushpop class PriorityQueue: def __init__(self, heap): ''' heap ... list ''' self.heap = heap heapify(self.heap) def push(self, item): heappush(self.heap, item) def pop(self): return heappop(self.heap) def pushpop(self, item): return heappushpop(self.heap, item) def __call__(self): return self.heap heap = [] # ヒープといっても順序を工夫したただのリスト q = PriorityQueue(heap) q.push((-(A[0] + B[0] + C[0]), 0, 0, 0)) ans = [] for k_th in range(1, K+1): heap_max, i, j, k = q.pop() # print(heap_max) ans.append(-heap_max) for di, dj, dk in zip([1, 0, 0], [0, 1, 0], [0, 0, 1]): i_new, j_new, k_new = i + di, j + dj, k + dk if i_new >= X or j_new >= Y or k_new >= Z: continue tmp = (-(A[i_new] + B[j_new] + C[k_new]), i_new, j_new, k_new) if tmp in q(): # ここが計算量がおおい continue q.push(tmp) print(*ans, sep='\n')
# ヒープに要素を追加、一番でかいのを取り出すという操作を最大3000回やるやり方 # これもなかなか早い # ヒープは追加も要素の取り出しもO(log n)で住むので、 # 計算オーダーはO(K log n)で済む(nはヒープの要素数)らしいが # not in があるのでO(n K log n)では? # pythonのヒープは使い方に癖があるのでこの機会に習得しよう import sys read = sys.stdin.readline def read_ints(): return list(map(int, read().split())) X, Y, Z, K = read_ints() A = read_ints() B = read_ints() C = read_ints() A.sort(reverse=True) B.sort(reverse=True) C.sort(reverse=True) from heapq import heapify, heappop, heappush, heappushpop class PriorityQueue: def __init__(self, heap): ''' heap ... list ''' self.heap = heap heapify(self.heap) def push(self, item): heappush(self.heap, item) def pop(self): return heappop(self.heap) def pushpop(self, item): return heappushpop(self.heap, item) def __call__(self): return self.heap heap = [] # ヒープといっても順序を工夫したただのリスト q = PriorityQueue(heap) q.push((-(A[0] + B[0] + C[0]), 0, 0, 0)) considered = set() ans = [] for k_th in range(1, K+1): heap_max, i, j, k = q.pop() ans.append(-heap_max) for di, dj, dk in zip([1, 0, 0], [0, 1, 0], [0, 0, 1]): i_new, j_new, k_new = i + di, j + dj, k + dk if i_new >= X or j_new >= Y or k_new >= Z: continue if (i_new, j_new, k_new) in considered: continue considered.add((i_new, j_new, k_new)) q.push((-(A[i_new] + B[j_new] + C[k_new]), i_new, j_new, k_new)) print(*ans, sep='\n')
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) sum_list = [] for a_i in range(x): for b_i in range(y): for c_i in range(z): if a_i*b_i*c_i > k: continue sum_list.append(a[a_i]+b[b_i]+c[c_i]) sum_list.sort(reverse=True) for i in range(k): print((sum_list[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) sum_list = [] for a_i in range(x): for b_i in range(y): if a_i*b_i > k: break for c_i in range(z): if a_i*b_i*c_i > k: break sum_list.append(a[a_i]+b[b_i]+c[c_i]) sum_list.sort(reverse=True) for i in range(k): print((sum_list[i]))
p03078
import sys input = sys.stdin.readline X, Y, Z, K = map(int, 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()] ablst = [m + n for n in b for m in a] ablst.sort(reverse=True) c.sort(reverse=True) abclst = [m + n for n in c[:K] for m in ablst[:K]] abclst.sort(reverse=True) print(*abclst[:K], sep='\n')
import sys input = sys.stdin.readline X, Y, Z, K = map(int, 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) ablst = [m + n for n in b for m in a] ablst.sort(reverse=True) c.sort(reverse=True) abclst = [m + n for n in c[:K] for m in ablst[:K]] abclst.sort(reverse=True) print(*abclst[:K], sep='\n')
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())) sum = [] for x in range(X): for y in range(Y): for z in range(Z): sum.append(A[x] + B[y] + C[z]) sum.sort(reverse=True) for i in range(K): print((sum[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) A = A[:K+1] B = B[:K+1] C = C[:K+1] E = [] for a in range(len(A)): for b in range(len(B)): E.append(A[a]+B[b]) E.sort(reverse=True) E = E[:K+1] ans = [] for c in range(len(C)): for e in range(len(E)): ans.append(C[c]+E[e]) 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())) E = [] for a in range(len(A)): for b in range(len(B)): E.append(A[a]+B[b]) E.sort(reverse=True) E = E[:K] ans = [] for c in range(len(C)): for e in range(len(E)): ans.append(C[c]+E[e]) 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) sum = [] for x in range(X): for y in range(Y): for z in range(Z): if (x+1)*(y+1)*(z+1) <= K: sum.append(A[x] + B[y] + C[z]) else: break sum.sort(reverse=True) for i in range(K): print((sum[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 = [] for i in range(X): for j in range(Y): AB.append(A[i] + B[j]) AB.sort(reverse=True) #print(AB) AB = AB[:K] ABC = [] for i in range(len(AB)): for j in range(Z): ABC.append(AB[i] + C[j]) ABC.sort(reverse=True) ABC = ABC[:K] for i in ABC: print(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) ABC = [] for x in range(X): for y in range(Y): for z in range(Z): if (x+1)*(y+1)*(z+1) <= K: ABC.append(A[x]+B[y]+C[z]) else: break ABC.sort(reverse=True) for i in range(K): print((ABC[i]))
p03078
x = 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() a.reverse() b.sort() b.reverse() c.sort() c.reverse() l = [] for i in range(x[0]): for j in range(x[1]): for k in range(x[2]): l.append(a[i]+b[j]+c[k]) l.sort() l.reverse() for i in range(x[3]): print((l[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())) d = [] for xx in a: for yy in b: d.append(xx+yy) d.sort() d.reverse() e = [] if len(d)>3000: for i in range(3000): for zz in c: e.append(d[i]+zz) else: for xy in d: for zz in c: e.append(xy+zz) e.sort() e.reverse() for i in range(k): print((e[i]))
p03078
from bisect import bisect_left 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())) bc = [x + y for y in c for x in b] bc.sort() bcl = len(bc) def bs_l(f, high, low=0): l, r = low-1, high+1 while r - l > 1: x = (l + r) // 2 if f(x): l = x else: r = x return l def detect(s): cnt = 0 for x in a: t = max(0, s-x) cnt += bcl - bisect_left(bc, t) return cnt >= k res = bs_l(detect, 10**10+1) ans = [] for x in a: t = max(0, res-x) for i in range(bcl-1, bisect_left(bc, t)-1, -1): ans.append(x + bc[i]) ans.sort(reverse=True) print(*ans[:k], sep="\n")
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) bc = [x + y for y in c for x in b] bc.sort(reverse=True) ans = [x + y for y in a for x in bc[:k]] ans.sort(reverse=True) print(*ans[:k], sep="\n")
p03078
import math import sys X,Y,Z,K=list(map(int,input().split())) x=sorted(list(map(int,input().split())),reverse=True) y=sorted(list(map(int,input().split())),reverse=True) z=sorted(list(map(int,input().split())),reverse=True) """ if X*Y*Z<=3000: ans=[] for i in range(X): for j in range(Y): for k in range(Z): ans.append(x[i]+y[j]+z[k]) ans.sort() for i in range(min(3000,X*Y*Z)): print(ans[i]) sys.exit() """ yz=[] for i in range(Y): yz=yz+[ y[i]+z[j] for j in range(Z)] yz.sort(reverse=True) if len(yz)>K: yz=yz[:K] n=len(yz) ans=[] for i in range(X): tmp=[yz[j]+x[i] for j in range(len(yz))] ans =ans+tmp ans.sort(reverse=True) for i in range(K): print((ans[i]))
import math import sys X,Y,Z,K=list(map(int,input().split())) x=sorted(list(map(int,input().split())),reverse=True) y=sorted(list(map(int,input().split())),reverse=True) z=sorted(list(map(int,input().split())),reverse=True) """ if X*Y*Z<=3000: ans=[] for i in range(X): for j in range(Y): for k in range(Z): ans.append(x[i]+y[j]+z[k]) ans.sort() for i in range(min(3000,X*Y*Z)): print(ans[i]) sys.exit() """ ans=[] for i in range(min(X,K)): tmp1=math.ceil(K/(i+1)) for j in range(min(Y,tmp1)): tmp2=math.ceil(tmp1/(j+1)) for k in range(min(Z,tmp2)): ans.append(x[i]+y[j]+z[k]) ans.sort(reverse=True) for i in range(K): print((ans[i]))
p03078
input_out_data = input().split(" ") cake_sum_point = [] for i in range(4): input_out_data[i] = int(input_out_data[i]) cake_A = input().split(" ") cake_B = input().split(" ") cake_C = input().split(" ") for k in range(input_out_data[0]): cake_A[k] = int(cake_A[k]) cake_A.sort(reverse=True) for k in range(input_out_data[1]): cake_B[k] = int(cake_B[k]) cake_B.sort(reverse=True) for k in range(input_out_data[2]): cake_C[k] = int(cake_C[k]) cake_C.sort(reverse=True) for i in range(input_out_data[0]): for k in range(input_out_data[1]): for j in range(input_out_data[2]): cake_sum_point.append(cake_A[i]+cake_B[k]+cake_C[j]) cake_sum_point.sort(reverse=True) for i in range(input_out_data[3]): print((cake_sum_point[i]))
input_out_data = input().split(" ") cake_sum_point = [] for i in range(4): input_out_data[i] = int(input_out_data[i]) cake_A = input().split(" ") cake_B = input().split(" ") cake_C = input().split(" ") for k in range(input_out_data[0]): cake_A[k] = int(cake_A[k]) cake_A.sort(reverse=True) for k in range(input_out_data[1]): cake_B[k] = int(cake_B[k]) cake_B.sort(reverse=True) for k in range(input_out_data[2]): cake_C[k] = int(cake_C[k]) cake_C.sort(reverse=True) for i in range(input_out_data[0]): for k in range(input_out_data[1]): for j in range(input_out_data[2]): if (i+1)*(k+1)*(j+1)<=input_out_data[3]: cake_sum_point.append(cake_A[i]+cake_B[k]+cake_C[j]) cake_sum_point.sort(reverse=True) for i in range(input_out_data[3]): print((cake_sum_point[i]))
p03078
x,y,z,q=list(map(int,input().split())) a=sorted(map(int,input().split()),reverse=True) b=sorted(map(int,input().split()),reverse=True) c=sorted(map(int,input().split()),reverse=True) def bisect(l,r): cnt=(l+r)//2 if cnt==l: return l-1+judge(l) if judge(cnt): return bisect(cnt+1,r) else: return bisect(l,cnt) def judge(thr): m=0 for i in range(x): for j in range(y): for k in range(z): if i*j*k>q or a[i]+b[j]+c[k]<thr: break m+=1 if m>=q: return True return False def make(thr): m=0 l=[] for i in a: for j in b: for k in c: n=i+j+k if n<thr+1: break m+=1 l+=[n] l.sort(reverse=True) return l+[thr]*(q-len(l)) thr=bisect(0,a[0]+b[0]+c[0]+1) ans=make(thr) for w in ans: print(w)
x,y,z,q=list(map(int,input().split())) a=sorted(map(int,input().split()),reverse=True) b=sorted(map(int,input().split()),reverse=True) c=sorted(map(int,input().split()),reverse=True) l=[] for i in range(x): for j in range(y): if i*j>q: break for k in range(z): if i*j*k>q: break l+=[a[i]+b[j]+c[k]] l.sort(reverse=True) for w in l[:q]: print(w)
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())) if X<Y and X<Z: X,Z=Z,X A,C=C,A elif Y<X and Y<Z: Y,Z=Z,Y B,C=C,Y C=sorted(C,reverse=True) k=min(K,X*Y) 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[:K]],reverse=True)[:K] for x in ABC: print(x)
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 i in range(X): if i+1>K: break 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 ans.append(A[i]+B[j]+C[k]) ans=sorted(ans,reverse=True) for a in ans[: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())) sum = 0 ans = [] ans2 = [] for i in range(X): for j in range(Y): sum = A[i] + B[j] ans.append(sum) ans.sort(reverse=True) for i in range(min(K,len(ans))): for j in range(Z): sum = ans[i] + C[j] ans2.append(sum) ans2.sort(reverse=True) for l in range(K): print((ans2[l]))
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 i in range(X): for j in range(Y): if (i+1)*(j+1) > K: break for t in range(Z): if (i+1)*(j+1)*(t+1) > K: break ans.append(A[i]+B[j]+C[t]) ans.sort(reverse=True) for l in range(K): print((ans[l]))
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) done = [[[True for _ in range(Z+1)] for _ in range(Y+1)] for _ in range(Z+1)] h = [] heapq.heappush(h, (-(A[0]+B[0]+C[0]), 0, 0, 0)) # リストaのheap化 done[0][0][0] = False for _ in range(K): p, i, j, k = heapq.heappop(h) # print(h) print((-p)) if done[i+1][j][k] and i+1 < X: # heap化されたリストaに要素xを追加 heapq.heappush(h, (-(A[i+1]+B[j]+C[k]), i+1, j, k)) # print(h) done[i+1][j][k] = False if done[i][j+1][k] and j+1 < Y: # heap化されたリストaに要素xを追加 heapq.heappush(h, (-(A[i]+B[j+1]+C[k]), i, j+1, k)) # print(h) done[i][j+1][k] = False if done[i][j][k+1] and k+1 < Z: # heap化されたリストaに要素xを追加 heapq.heappush(h, (-(A[i]+B[j]+C[k+1]), i, j, k+1)) # print(h) done[i][j][k+1] = False
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) # done = [[[True for _ in range(Z+1)] for _ in range(Y+1)] for _ in range(Z+1)] done = [] h = [] heapq.heappush(h, (-(A[0]+B[0]+C[0]), 0, 0, 0)) # リストaのheap化 done.append((0, 0, 0)) for _ in range(K): p, i, j, k = heapq.heappop(h) # print(h) print((-p)) if (i+1, j, k) not in done and i+1 < X: # heap化されたリストaに要素xを追加 heapq.heappush(h, (-(A[i+1]+B[j]+C[k]), i+1, j, k)) # print(h) done.append((i+1, j, k)) if (i, j+1, k) not in done and j+1 < Y: # heap化されたリストaに要素xを追加 heapq.heappush(h, (-(A[i]+B[j+1]+C[k]), i, j+1, k)) # print(h) done.append((i, j+1, k)) if (i, j, k+1) not in done and k+1 < Z: # heap化されたリストaに要素xを追加 heapq.heappush(h, (-(A[i]+B[j]+C[k+1]), i, j, k+1)) # print(h) done.append((i, j, k+1))
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) done = [[[False for k in range(Z)] for j in range(Y)] for i in range(X)] done[0][0][0] = True hq = [(-(A[0]+B[0]+C[0]), 0, 0, 0)] heapq.heapify(hq) # リストhqのheap化 ans = 0 D = [(1, 0, 0), (0, 1, 0), (0, 0, 1)] for _ in range(K): s, i, j, k = heapq.heappop(hq) # heap化されたリストhqから最小値を削除&その最小値を出力 print((-s)) for d in D: ni, nj, nk = i+d[0], j+d[1], k+d[2] if ni < X and nj < Y and nk < Z and done[ni][nj][nk] is False: # heap化されたリストhqに要素xを追加 heapq.heappush(hq, (-(A[ni]+B[nj]+C[nk]), ni, nj, nk)) done[ni][nj][nk] = True
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) done = {(0, 0, 0)} hq = [(-(A[0]+B[0]+C[0]), 0, 0, 0)] heapq.heapify(hq) # リストhqのheap化 ans = 0 D = [(1, 0, 0), (0, 1, 0), (0, 0, 1)] for _ in range(K): s, i, j, k = heapq.heappop(hq) # heap化されたリストhqから最小値を削除&その最小値を出力 print((-s)) for d in D: ni, nj, nk = i+d[0], j+d[1], k+d[2] if ni < X and nj < Y and nk < Z and (ni, nj, nk) not in done: # heap化されたリストhqに要素xを追加 heapq.heappush(hq, (-(A[ni]+B[nj]+C[nk]), ni, nj, nk)) done.add((ni, nj, nk))
p03078
import sys from heapq import heappush,heapify,heappop 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())) d = [i + j for i in a for j in b] d.sort(reverse=1) c.sort(reverse=1) q = [(-d[0] - c[0], 0, 0)] for _ in range(k): v, s, t = heappop(q) print((-v)) if t + 1 < z: heappush(q, (-d[s] - c[t + 1], s, t + 1)) if t == 0 and s + 1 < x * y: heappush(q, (-d[s + 1] - c[0], s + 1, 0))
# O(klog(k))解法 多分... import sys from heapq import heappush,heapify,heappop input = sys.stdin.readline 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())) def make_kth(A, B): n, m = len(A), len(B) A.sort(reverse=1) B.sort(reverse=1) q = [(-A[0] - B[0], 0, 0)] r=[] for _ in range(min(k, n * m)): v, s, t = heappop(q) r.append(-v) if t + 1 < m: heappush(q, (-A[s] - B[t + 1], s, t + 1)) if t == 0 and s + 1 < n: heappush(q, (-A[s + 1] - B[0], s + 1, 0)) return r r = make_kth(a, b) r = make_kth(c, r) print(*r,sep="\n")
p03078
# -*- coding: utf-8 -*- 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) count = min(x * z, k) ac = list() ans = list() for ai in a: for ci in c: ac.append(ai + ci) for bi in b: for ac_i in sorted(ac, reverse=True)[:count]: ans.append(bi + ac_i) for j in sorted(ans, reverse=True)[:k]: print(j) if __name__ == '__main__': main()
# -*- coding: utf-8 -*- 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) ac = list() for ai in a: for ci in c: ac.append(ai + ci) count = min(x * z, k) acs = sorted(ac, reverse=True)[:count] ans = list() for bi in b: for ac_i in acs: ans.append(bi + ac_i) for j in sorted(ans, reverse=True)[:k]: print(j) if __name__ == '__main__': main()
p03078
from heapq import heappop,heappush;import sys;input=sys.stdin.readline x,y,z,k=list(map(int,input().split()));a,b,c=list(map(int,input().split())),list(map(int,input().split())),list(map(int,input().split())) q,h,l=[],[],0 for i in a: for j in b:heappush(q,-(i+j));l+=1 for _ in range(min(l,k)): t=heappop(q) for i in c:heappush(h,t-i) for i in range(k):print((-heappop(h)))
x,y,z,k=list(map(int,input().split()));a,b,c=list(map(int,input().split())),list(map(int,input().split())),list(map(int,input().split())) aa=[] for i in a: for j in b:aa.append(i+j) aa.sort(reverse=1) aa=aa[:k+1] s=[] for i in aa: for j in c:s.append(i+j) s.sort(reverse=1) for i in range(k):print((s[i]))
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()] ans = [] for x in range(X): for y in range(Y): for z in range(Z): ans.append(A[x]+B[y]+C[z]) ans.sort(reverse=True) for k in range(K): print((ans[k]))
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()] ans = [] for x in range(X): for y in range(Y): ans.append(A[x]+B[y]) ans.sort(reverse=True) C.sort(reverse=True) ans2 = [] for k in range(min(K,X*Y)): for z in range(min(Z,K)): ans2.append(ans[k]+C[z]) ans2.sort(reverse=True) for k in range(K): print((ans2[k]))
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())) x_pls_y = [] for i in range(x): for j in range(y): x_pls_y.append(a[i]+b[j]) x_pls_y.sort(reverse=True) xy_pls_z = [] for i in range(min(3000,x*y)): for j in range(z): xy_pls_z.append(x_pls_y[i]+c[j]) xy_pls_z.sort(reverse=True) for i in range(k): print((xy_pls_z[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) kouho = [] for i in range(x): for j in range(y): for k in range(z): if (i+1)*(j+1)*(k+1) > K: break kouho.append(a[i]+b[j]+c[k]) kouho.sort(reverse=True) for i in range(K): print((kouho[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())) ab = list() for a in A: for b in B: ab.append(a+b) ab.sort(reverse=True) C.sort(reverse=True) abc = [] for a in ab[:k]: for b in C: abc.append(a+b) abc.sort(reverse=True) print(*abc[:k], sep="\n")
import heapq as hq 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: hq.heappush(ab, -a-b) abc = [] cnt = 0 while cnt < k and ab: cnt += 1 a = hq.heappop(ab) for b in C: hq.heappush(abc, a-b) cnt = 0 while cnt < k: print((-hq.heappop(abc))) cnt += 1
p03078
import heapq X, Y, Z, K = list(map(int, input().split(" "))) A = sorted(map(int, input().split(" ")), reverse=True) B = sorted(map(int, input().split(" ")), reverse=True) C = sorted(map(int, input().split(" ")), reverse=True) anslist = [] flag = [[[False for _ in range(K)] for _ in range(K)] for _ in range(K)] heapq.heappush(anslist, (-(A[0]+B[0]+C[0]), "000")) count = 0 while count < K: p = heapq.heappop(anslist) print((p[0]*(-1))) count += 1 # push a, b, c = list(map(int, p[1])) for i, j, k in [[1, 0, 0], [0, 1, 0], [0, 0, 1]]: if a+i >= X or b+j >= Y or c+k >= Z: continue if not flag[a+i][b+j][c+k]: flag[a+i][b+j][c+k] = True tmp = str(a+i)+str(b+j)+str(c+k) heapq.heappush(anslist, (-(A[a+i]+B[b+j]+C[c+k]), tmp))
import heapq class Delicious (object): def __init__(self, x, y, z): self.x = x self.y = y self.z = z def total(self): return(A[self.x] + B[self.y] + C[self.z]) def __lt__(self, other): return self.total() > other.total() X, Y, Z, K = list(map(int, input().split(" "))) A = sorted(map(int, input().split(" ")), reverse=True) B = sorted(map(int, input().split(" ")), reverse=True) C = sorted(map(int, input().split(" ")), reverse=True) ds = [] heapq.heappush(ds, Delicious(0, 0, 0)) check = {} for _ in range(K): d = heapq.heappop(ds) while (d.x, d.y, d.z) in check: d = heapq.heappop(ds) print((d.total())) check[d.x, d.y, d.z] = True if d.x < X-1: heapq.heappush(ds, Delicious(d.x+1, d.y, d.z)) if d.y < Y-1: heapq.heappush(ds, Delicious(d.x, d.y+1, d.z)) if d.z < Z-1: heapq.heappush(ds, Delicious(d.x, d.y, d.z+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) useA = [a.pop(0)] useB = [b.pop(0)] useC = [c.pop(0)] if len(a) == 0: a.append(0) if len(b) == 0: b.append(0) if len(c) == 0: c.append(0) while True: if a[0] == b[0] == c[0] == 0: break if a[0] >= b[0] and a[0] >= c[0]: useA.append(a.pop(0)) if len(a) == 0: a.append(0) elif b[0] >= a[0] and b[0] >= c[0]: useB.append(b.pop(0)) if len(b) == 0: b.append(0) elif c[0] >= b[0] and c[0] >= a[0]: useC.append(c.pop(0)) if len(c) == 0: c.append(0) # print( len(useA) * len(useB) * len(useC)) if 1000*k**2 <= len(useA) * len(useB) * len(useC): break ans = [] #print(useA, useB, useC) for i in range(len(useA)): for j in range(len(useB)): for m in range(len(useC)): ans.append(useA[i] + useB[j] + useC[m]) 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) def search(a, b): ret = [] al = len(a) bl = len(b) for i in range(min(al, k)): for j in range(min(bl, k-i)): ret.append(a[i] + b[j]) ret.sort(reverse = True) return ret d = search(a, b) e = search(c, d) for i in range(k): print((e[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) a=a[:k] b=b[:k] sum_ab=[] for i in a: for j in b: sum_ab.append(i+j) sorted(sum_ab,reverse=True) sum_abc=[] for i in sum_ab: for j in c: sum_abc.append(i+j) sum_abc.sort(reverse=True) for v in sum_abc[:k]: print(v)
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) sum_ab=[] for i in a: for j in b: sum_ab.append(i+j) sum_ab.sort(reverse=True) sum_ab= sum_ab[:k] sum_abc=[] for i in sum_ab: for j in c: sum_abc.append(i+j) sum_abc.sort(reverse=True) for v in sum_abc[:k]: print(v)
p03078
import sys from bisect import bisect_left as bi_l, bisect_right as bi_r x, y, z, k = map(int, sys.stdin.readline().split()) a, b, c = (sorted(map(int, sys.stdin.readline().split())) for _ in range(3)) def count_atleast_k(border): combs = 0 for i in range(x): for j in range(y): combs += z - bi_r(c, border - a[i] - b[j]) return combs >= k def main(): hi = 3 * 10 ** 10 + 1 lo = 2 while lo + 1 < hi: border = (lo + hi) // 2 if count_atleast_k(border): lo = border else: hi = border res = [] for i in range(x-1, -1, -1): if hi - a[i] > b[-1] + c[-1]: break for j in range(y-1, -1, -1): if hi - a[i] - b[j] > c[-1]: break for k in range(z-1, -1, -1): if hi - a[i] - b[j] - c[k] > 0: break res.append(a[i] + b[j] + c[k]) return sorted(res, reverse=True) if __name__ == '__main__': ans = main() print(*ans, sep='\n')
import sys from heapq import heappush, heappop x, y, z, K = map(int, sys.stdin.readline().split()) a, b, c = (sorted(map(int, sys.stdin.readline().split()), reverse=True) for _ in range(3)) def main(): cand = [(-(a[0] + b[0] + c[0]), 0, 0, 0)] added = set([(0, 0, 0)]) for _ in range(K): s, i, j, k = heappop(cand) yield -s if i + 1 < x and not (i+1, j, k) in added: heappush(cand, (s + a[i] - a[i+1], i+1, j, k)) added.add((i+1, j, k)) if j + 1 < y and not (i, j+1, k) in added: heappush(cand, (s + b[j] - b[j+1], i, j+1, k)) added.add((i, j+1, k)) if k + 1 < z and not (i, j, k+1) in added: heappush(cand, (s + c[k] - c[k+1], i, j, k+1)) added.add((i, j, k+1)) if __name__ == '__main__': ans = main() print(*ans, sep='\n')
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, Bで総当たり、上位K個をスタック tmp = [a+b for a in A for b in B] tmp.sort(reverse=True) tmp = tmp[:K] # 残りのc個に対しても総当たり ans = [t+c for t in tmp for c in C] ans.sort(reverse=True) ans = ans[:K] for s in ans: print(s)
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, Bで総当たり、上位K個をスタック tmp = [a+b for a in A for b in B] tmp.sort(reverse=True) tmp = tmp[:K] # 残りのc個に対しても総当たり ans = [t+c for t in tmp for c in C] ans.sort(reverse=True) ans = ans[:K] for s in ans: 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())) a.sort(reverse = True) b.sort(reverse = True) c.sort(reverse = True) li = [] for i in a: for j in b: li.append(i + j) li.sort(reverse = True) li = li[:min(k,x*y)] box = [] for i in li: for j in c: box.append(i + j) box.sort(reverse = True) for i in range(k): print((box[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) li = [] box = [] for i in a: for j in b: li.append(i + j) li.sort(reverse = True) li = li[:min(k,x*y)] for i in c: for j in li: box.append(i + j) box.sort(reverse = True) for i in range(k): print((box[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) tot = [] for i in range(X): for j in range(Y): for k in range(Z): if(i*j*k > K): break else: tot.append(a[i] + b[j] + c[k]) tot.sort() for i in range(K): print((tot[-(i+1)]))
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) tot = [] for i in range(X): for j in range(Y): for k in range(Z): if((i+1)*(j+1)*(k+1) <= K): tot.append(a[i] + b[j] + c[k]) else: break tot.sort(reverse = True) for i in range(K):print((tot[i]))
p03078
import heapq #Aの中でa番目、Bの中でb番目、Cの中でc番目のものがabc > Kの時、大きい順のK番目以内に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) h = [] check = [[[0] * Z for _ in range(Y)] for _ in range(X)] heapq.heappush(h, [-(A[0]+B[0]+C[0]), 0, 0, 0]) check[0][0][0] = 1 for count in range(K): ans = heapq.heappop(h) i, j , k = ans[1], ans[2], ans[3] print((-ans[0])) if i + 1 < X: if check[i+1][j][k] == 0: heapq.heappush(h, [-(A[i+1]+B[j]+C[k]), i+1, j, k]) check[i+1][j][k] = 1 if j + 1 < Y: if check[i][j+1][k] == 0: heapq.heappush(h, [-(A[i]+B[j+1]+C[k]), i, j+1, k]) check[i][j+1][k] = 1 if k + 1 < Z: if check[i][j][k+1] == 0: heapq.heappush(h, [-(A[i]+B[j]+C[k+1]), i, j, k+1]) check[i][j][k+1] = 1
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) bi_comb = [] for i in range(min(X, K)): for j in range(min(Y, K)): if (i+1)*(j+1) <= K: bi_comb += [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: tri_comb += [bi_comb[k]+C[l]] tri_comb.sort(reverse = True) print (*tri_comb[:K], sep='\n')
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())) D=[] for i in range(X): for j in range(Y): D.append(A[X-1-i]+B[Y-1-j]) D.sort() ans=[] for i in range(min(K,len(D))): for j in range(min(K,Z)): ans.append(D[len(D)-1-i]+C[Z-1-j]) ans.sort() for i in range(K): print((ans[len(ans)-1-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: break else: 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())) AB=[a+b for a in A for b in B] AB.sort(reverse=True) ABC=[ab+c for ab in AB[:min(k,x*y)] for c in 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=[a+b for a in A for b in B] AB.sort(reverse=True) ABC=[ab+c for ab in AB[:min(k,x*y)] for c in 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())) ans=[] for i in range(x): for j in range(y): for n in range(z): ans.append(a[i]+b[j]+c[n]) ans.sort() ans=ans[::-1] cnt=0 while cnt!=k: print((ans[cnt])) cnt+=1
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=[s+t for s in a for t in b] ab.sort() ab=ab[-1:-k-1:-1] abc=[s+t for s in ab for t in c] abc.sort() abc=abc[-1:-k-1:-1] for i in range(len(abc)): 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=[s+t for s in a for t in b] ab.sort() ab=ab[-1:-k-1:-1] abc=[s+t for s in ab for t in c] abc.sort() abc=abc[-1:-k-1:-1] for i in range(len(abc)): 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=sorted([s+t for s in a for t in b])[-1:-k-1:-1] abc=sorted([s+t for s in ab for t in c])[-1:-k-1:-1] 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())) temp_sum = [] for i in range(X): for j in range(Y): for k in range(Z): temp_sum.append(A[i] + B[j] + C[k]) def merge_sort(arr): if len(arr) <= 1: return arr mid = len(arr) // 2 # ここで分割を行う left = arr[:mid] right = arr[mid:] # 再帰的に分割を行う left = merge_sort(left) right = merge_sort(right) # returnが返ってきたら、結合を行い、結合したものを次に渡す return merge(left, right) def merge(left, right): merged = [] l_i, r_i = 0, 0 # ソート済み配列をマージするため、それぞれ左から見ていくだけで良い while l_i < len(left) and r_i < len(right): # ここで=をつけることで安定性を保っている if left[l_i] <= right[r_i]: merged.append(left[l_i]) l_i += 1 else: merged.append(right[r_i]) r_i += 1 # 上のwhile文のどちらかがFalseになった場合終了するため、あまりをextendする if l_i < len(left): merged.extend(left[l_i:]) if r_i < len(right): merged.extend(right[r_i:]) return merged ans = merge_sort(temp_sum) for i in range(K): print((ans[len(ans) - 1 - 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 = [] A.sort() A.reverse() B.sort() B.reverse() C.sort() C.reverse() for i in range(min(K,len(A))): if K // (i+1) > 0: for j in range(min(K // (i+1),len(B))): if K // ((i+1) * (j+1)) > 0: for l in range(min(K // ((i+1) * (j+1)),len(C))): ans.append(A[i] + B[j] + C[l]) ans.sort() ans.reverse() 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.sort(reverse=True) b.sort(reverse=True) c.sort(reverse=True) ab=[] for i in a: for j in b: ab.append(i+j) ab.sort(reverse=True) ab=ab[:k] c=c[:k] abc=[] for i in ab: for j in c: abc.append(i+j) abc.sort(reverse=True) for i in abc[:k]: print(i)
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 = sorted(x+y for x in a for y in b)[:-k-1:-1] abc = sorted(x+y for x in ab[:k] for y in c)[:-k-1:-1] print(*abc, sep='\n')
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 = sorted(x+y for x in a for y in b)[:-k-1:-1] c = c[:k] abc = [] for i in ab: for j in c: abc.append(i+j) abc.sort(reverse=True) print(*abc[:k], sep="\n")
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 = sorted(i+j for i in a for j in b)[:-k-1:-1] c = c[:k] abc = sorted(i+j for i in ab for j in c)[:-k-1:-1] print(*abc[:k], sep="\n")
p03078
import sys input = sys.stdin.readline 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 = sorted(i+j for i in a for j in b)[:-k-1:-1] c = c[:k] abc = sorted(i+j for i in ab for j in c)[:-k-1:-1] print(*abc[:k], sep="\n")
import sys input = sys.stdin.readline x, y, z, k = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) c=sorted(int(i) for i in input().split()) a.sort(reverse=True) b.sort(reverse=True) #c.sort(reverse=True) ab = sorted(i+j for i in a for j in b)[:-k-1:-1] c = c[:k] abc = sorted(i+j for i in ab for j in c)[:-k-1:-1] print(*abc[:k], sep="\n")
p03078
import sys input = sys.stdin.readline x, y, z, k = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) c=sorted(int(i) for i in input().split())[:-k-1:-1] a.sort(reverse=True) b.sort(reverse=True) #c.sort(reverse=True) ab = sorted(i+j for i in a for j in b)[:-k-1:-1] abc = sorted(i+j for i in ab for j in c)[:-k-1:-1] print(*abc[:k], sep="\n")
import sys input = sys.stdin.readline x, y, z, k = map(int, input().split()) a = sorted(int(i) for i in input().split()) b = sorted(int(i) for i in input().split()) c = sorted(int(i) for i in input().split()) #a.sort(reverse=True) #b.sort(reverse=True) #c.sort(reverse=True) ab = sorted(i+j for i in a for j in b)[:-k-1:-1] abc = sorted(i+j for i in ab for j in c)[:-k-1:-1] print(*abc[:k], sep="\n")
p03078
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians from itertools import permutations, combinations, product from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits 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())) sys.setrecursionlimit(10 ** 9) INF = float('inf') MOD = 10 ** 9 + 7 X, Y, Z, K = MAP() A = LIST() B = LIST() C = LIST() A=sorted(A)[::-1] B=sorted(B)[::-1] C=sorted(C)[::-1] ans = [] for i in range(len(A)): if i > K: continue for j in range(len(B)): if i * j > K: continue for k in range(len(C)): if i * j * k > K: continue else: ans.append(A[i]+B[j]+C[k]) for i in sorted(ans)[::-1][0:K]: print(i)
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians from itertools import permutations, combinations, product from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits 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())) sys.setrecursionlimit(10 ** 9) INF = float('inf') MOD = 10 ** 9 + 7 X, Y, Z, K = MAP() A = LIST() B = LIST() C = LIST() A=sorted(A)[::-1] B=sorted(B)[::-1] C=sorted(C)[::-1] ans = [] 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: ans.append(A[i]+B[j]+C[k]) else: break for i in sorted(ans)[::-1][0:K]: print(i)
p03078
#!/usr/bin/python import sys import heapq R=lambda:list(map(int,sys.stdin.readline().split())) xa,xb,xc,k=R() a=sorted(R()) b=sorted(R()) c=sorted(R()) h=set() q=[[-(a[-1]+b[-1]+c[-1]),xa-1,xb-1,xc-1]] for _ in range(k): x,ya,yb,yc=heapq.heappop(q) print((-x)) if ya>0 and (ya-1,yb,yc) not in h: h.add((ya-1,yb,yc)) heapq.heappush(q,[x+a[ya]-a[ya-1],ya-1,yb,yc]) if yb>0 and (ya,yb-1,yc) not in h: h.add((ya,yb-1,yc)) heapq.heappush(q,[x+b[yb]-b[yb-1],ya,yb-1,yc]) if yc>0 and (ya,yb,yc-1) not in h: h.add((ya,yb,yc-1)) heapq.heappush(q,[x+c[yc]-c[yc-1],ya,yb,yc-1])
import sys,heapq R=lambda:list(map(int,sys.stdin.readline().split())) x=list(R()) k=x.pop() a=[sorted(R())for _ in range(3)] h=set() q=[[-sum(e[-1] for e in a)]+[e-1 for e in x]] for _ in range(k): y=heapq.heappop(q) x=y.pop(0) print((-x)) for i in range(3): ny=list(y) ny[i]-=1 if y[i] and tuple(ny) not in h: h.add(tuple(ny)) heapq.heappush(q,[x+a[i][y[i]]-a[i][y[i]-1]]+ny)
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[0: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())) 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
import sys,bisect input = sys.stdin.readline 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())) ab = [] for e in a: for w in b: ab.append(e+w) ab.sort() ok = -1 ng = 10**11 while abs(ok-ng)>1: mid = (ok+ng)//2 cnt = 0 for e in c: cnt += len(ab)-bisect.bisect_left(ab,mid-e) if cnt >= k: ok = mid else: ng = mid res = [] for e in c: ind = bisect.bisect_left(ab,ok-e) for i in range(ind,len(ab)): res.append(e+ab[i]) res.sort() for i in range(1,k+1): print((res[-i]))
import sys,bisect input = sys.stdin.readline def main(): 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())) ab = [] for e in a: for w in b: ab.append(e+w) ab.sort() ok = -1 ng = 10**11 while abs(ok-ng)>1: mid = (ok+ng)//2 cnt = 0 for e in c: cnt += len(ab)-bisect.bisect_left(ab,mid-e) if cnt >= k: ok = mid else: ng = mid res = [] for e in c: ind = bisect.bisect_left(ab,ok-e) for i in range(ind,len(ab)): res.append(e+ab[i]) res.sort() for i in range(1,k+1): print((res[-i])) if __name__ == '__main__': main()
p03078