P6567 [NOI Online #3 Junior] Buying Watches

Description

Jimmy goes to Symbol's watch shop to buy watches. Jimmy only brought $n$ types of coins. The face value of the $i$-th type is $k_i$ yuan, and he has $a_i$ coins of that type. There are $m$ watches in Symbol's shop, and the price of the $i$-th watch is $t_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 $n$ and $m$, representing the number of coin types and the number of watches. The next $n$ lines each contain two space-separated integers $k_i$ and $a_i$, representing the face value and the count of the $i$-th coin type. The $(n+2)$-th line contains $m$ space-separated integers $t_i$, representing the price of each watch.

Output Format

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

Explanation/Hint

#### Explanation for Sample 1 - For the second watch, $19=6 \times 3+1=6 \times 2+5+1 \times 2$, so it can be made up exactly. - For the fourth watch, $1=1 \times 1$, so it can be made up exactly. - For the fifth watch, $7=5+2\times 1=6 \times 1+1$, so it can be made up exactly. #### Constraints - For $50\%$ of the testdata, it is guaranteed that $n\leq 10$, $m \leq 60$, $a_i \leq 20$, $k_i \leq 5000$, $t_i \leq 250$. - For $100\%$ of the testdata, it is guaranteed that $1 \leq n \leq 200$, $1 \leq m \leq 10^5$, $1 \leq a_i \leq 1000$, $1 \leq k_i \leq 500000$, $0 \leq t_i \leq 500000$. #### Notes data provider: @Jiao Yue Ban Sa Hua. Translated by ChatGPT 5