

Time Limit: 2 sec / Memory Limit: 1024 MB
配点 : 250 点
問題文
3 個の数列 A=(A_1,\ldots,A_N), B=(B_1,\ldots,B_M), C=(C_1,\ldots,C_L) が与えられます。
さらに数列 X=(X_1,\ldots,X_Q) が与えられるので、各 i=1,\ldots,Q に対して次の問題を解いてください。
問題:A,B,C からそれぞれ 1 個ずつ要素を選び、和を X_i にすることができるか?
制約
- 1 \leq N,M,L \leq 100
- 0 \leq A_i, B_i ,C_i \leq 10^8
- 1 \leq Q \leq 2\times 10^5
- 0 \leq X_i \leq 3\times 10^8
- 入力は全て整数である
入力
入力は以下の形式で標準入力から与えられる。
N A_1 \ldots A_N M B_1 \ldots B_M L C_1 \ldots C_L Q X_1 \ldots X_Q
出力
Q 行出力せよ。
i 行目には、A,B,C からそれぞれ 1 個ずつ要素を選び和を X_i にすることができるならば Yes
、できないならば No
と出力せよ。
入力例 1
3 1 2 3 2 2 4 6 1 2 4 8 16 32 4 1 5 10 50
出力例 1
No Yes Yes No
- A,B,C からそれぞれ 1 個ずつ要素を選び和を 1 にすることはできません。
- A,B,C からそれぞれ 1,2,2 を選ぶと和を 5 にすることができます。
- A,B,C からそれぞれ 2,4,4 を選ぶと和を 10 にすることができます。
- A,B,C からそれぞれ 1 個ずつ要素を選び和を 50 にすることはできません。
Score: 250 points
Problem Statement
You are given three sequences A=(A_1,\ldots,A_N), B=(B_1,\ldots,B_M), and C=(C_1,\ldots,C_L).
Additionally, a sequence X=(X_1,\ldots,X_Q) is given. For each i=1,\ldots,Q, solve the following problem:
Problem: Is it possible to select one element from each of A, B, and C so that their sum is X_i?
Constraints
- 1 \leq N,M,L \leq 100
- 0 \leq A_i, B_i ,C_i \leq 10^8
- 1 \leq Q \leq 2\times 10^5
- 0 \leq X_i \leq 3\times 10^8
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N A_1 \ldots A_N M B_1 \ldots B_M L C_1 \ldots C_L Q X_1 \ldots X_Q
Output
Print Q lines.
The i-th line should contain Yes
if it is possible to select one element from each of A, B, and C so that their sum is X_i, and No
otherwise.
Sample Input 1
3 1 2 3 2 2 4 6 1 2 4 8 16 32 4 1 5 10 50
Sample Output 1
No Yes Yes No
- It is impossible to select one element from each of A, B, and C so that their sum is 1.
- Selecting 1, 2, and 2 from A, B, and C, respectively, makes the sum 5.
- Selecting 2, 4, and 4 from A, B, and C, respectively, makes the sum 10.
- It is impossible to select one element from each of A, B, and C so that their sum is 50.