Official

C - A+B+C Editorial by en_translator


There are \((N\times M \times L)\) ways to choose one element from each of \(A\), \(B\), and \(C\); under the constraints \(N,M,L\leq 100\), there are at most \(10^6\) of them. By precomputing all of them and storing them in a set, one can answer each query in \(O(\log NML)\) time.

Sample code (Python)

input()
A=list(map(int,input().split()))
input()
B=list(map(int,input().split()))
input()
C=list(map(int,input().split()))

S=set()
for a in A:
  for b in B:
    for c in C:
      S.add(a+b+c)

input()
X=list(map(int,input().split()))

for x in X:
  if x in S:
    print("Yes")
  else:
    print("No")

posted:
last update: