#P8799. [蓝桥杯 2022 国 B] 齿轮

[蓝桥杯 2022 国 B] 齿轮

Problem Description

On this day, Xiaoming is assembling gears.

He has a total of nn gears. The radius of the ii-th gear is rir_{i}. He needs to assemble these nn gears in some order from left to right, so that after the leftmost gear starts rotating, the motion can be transmitted to the rightmost gear. Also, these gears can be used to increase or decrease the rotation speed (angular velocity).

Looking at these gears, Xiaoming suddenly has QQ questions: Is it possible to assemble these gears in some order so that the rotation speed of the rightmost gear is qiq_{i} times that of the leftmost gear?

Input Format

The input has Q+2Q+2 lines. The first line contains two positive integers n,Qn, Q, representing the number of gears and the number of queries.

The second line contains nn positive integers r1,r2,,rnr_{1}, r_{2}, \ldots, r_{n}, representing the radius of each gear.

The next QQ lines each contain one positive integer qiq_{i}, representing a query.

Output Format

Output QQ lines. For each query, if there exists at least one assembly plan that satisfies the condition, output YES; otherwise output NO.

5 3
4 2 3 3 1
2
4
6
YES
YES
NO

Hint

[Sample Explanation]

For query 11, one possible plan is: 23341.

For query 22, one possible plan is: 42331.

For query 33, there is no plan.

[Constraints and Notes on Testdata]

For 15%15\% of the testdata, it is guaranteed that n,Q100n, Q \leq 100.

For 30%30\% of the testdata, it is guaranteed that n,Q2000n, Q \leq 2000.

For 100%100\% of the testdata, n2n \ge 2, n,Q2×105n, Q \leq 2 \times 10^{5}, and ri,qi2×105r_{i}, q_{i} \leq 2 \times 10^{5}.

Lanqiao Cup 2022 National Finals, Group B, Problem I.

Translated by ChatGPT 5