SMRAD
Time limit1sMemory limit1024 MB
Given banknote values and a growing set of smelly values, for each query, decide whether amount X can be paid exactly using only non-smelly notes.
- Level
Medium5 of 10
- Topics
- Dynamic programming, Implementation
- Solved
- No attempts yet
Statement
After a few months of building houses in Germany and earning a lot of money, Josip returned to Croatia. On his first evening back, he decided to take his friend Josipa out to dinner. Since they both enjoy good food and drinks, Josip visited the ATM times that evening and withdrew kuna each time. The ATM holds kinds of banknotes with different values, and each kind is available in unlimited quantity.
Each time Josip came to withdraw money, a notice was posted on the ATM: "Dear customers, due to a malfunction, all banknotes of value will now smell bad. Thank you for your understanding!"
Once banknotes of some value become smelly, they stay smelly forever.
To avoid unpleasant situations with smelly banknotes, Josip wants to know whether the ATM can pay exactly kuna, either in one withdrawal or in several smaller payments that add up to , while being sure he will not receive a smelly banknote. Josip always asks the ATM for an amount that can be paid.
Input
The first line contains natural numbers and (), as given in the statement.
The second line contains natural numbers (, ) separated by spaces, where is the value of the first kind of banknote, the value of the second kind, and so on up to .
Each of the next lines contains two natural numbers and (, ) separated by a space, where is the amount Josip wants to withdraw on his -th visit, and is the value of the banknote that became smelly on his -th visit.
Output
On each of the lines, print "DA" if Josip can withdraw exactly kuna on his -th visit without receiving any smelly banknote, otherwise print "NE".
Hint
On the first visit, Josip cannot ask for 11 kuna in a single payment, because the ATM could give him a 5 kuna note and a smelly 6 kuna note. He can ask for three payments instead: one of 1 kuna and two of 5 kuna. None of these three payments can be made with the smelly note, and together they total the 11 kuna he wanted. On the second visit, Josip cannot withdraw 11 kuna without risking at least one smelly banknote.