#P6567. [NOI Online #3 入门组] 买表

[NOI Online #3 入门组] 买表

Problem Description

Jimmy goes to Symbol's watch shop to buy watches. Jimmy only brought nn types of coins. The face value of the ii-th type is kik_i yuan, and he has aia_i coins of that type. There are mm watches in Symbol's shop, and the price of the ii-th watch is tit_i yuan.

Symbol's watch shop cannot give change, so Jimmy can only buy a watch when he can make up exactly the required amount of money. Now, for each watch in the shop, Jimmy wants to know whether he can make up the exact amount to buy it.

Input Format

The first line contains two space-separated integers nn and mm, representing the number of coin types and the number of watches.

The next nn lines each contain two space-separated integers kik_i and aia_i, representing the face value and the count of the ii-th coin type.

The (n+2)(n+2)-th line contains mm space-separated integers tit_i, representing the price of each watch.

Output Format

Output a total of mm lines. For the ii-th line, output Yes if Jimmy can make up exactly the amount to buy the ii-th watch; otherwise output No. Note that only the first letter is uppercase.

3 5
1 2
5 1
6 3
3 19 21 1 7
No
Yes
No
Yes
Yes

Hint

Explanation for Sample 1

  • For the second watch, 19=6×3+1=6×2+5+1×219=6 \times 3+1=6 \times 2+5+1 \times 2, so it can be made up exactly.
  • For the fourth watch, 1=1×11=1 \times 1, so it can be made up exactly.
  • For the fifth watch, 7=5+2×1=6×1+17=5+2\times 1=6 \times 1+1, so it can be made up exactly.

Constraints

  • For 50%50\% of the testdata, it is guaranteed that n10n\leq 10, m60m \leq 60, ai20a_i \leq 20, ki5000k_i \leq 5000, ti250t_i \leq 250.
  • For 100%100\% of the testdata, it is guaranteed that 1n2001 \leq n \leq 200, 1m1051 \leq m \leq 10^5, 1ai10001 \leq a_i \leq 1000, 1ki5000001 \leq k_i \leq 500000, 0ti5000000 \leq t_i \leq 500000.

Notes

data provider: @Jiao Yue Ban Sa Hua.

Translated by ChatGPT 5