Under construction

Still being built. Things may change

SMRAD

Time limit1sMemory limit1024 MB

Summary
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 MM times that evening and withdrew XiX_i kuna each time. The ATM holds NN 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 CiC_i 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 XiX_i kuna, either in one withdrawal or in several smaller payments that add up to XiX_i, 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 NN and MM (1≤M≤N≤50001 \le M \le N \le 5000), as given in the statement.

The second line contains NN natural numbers AiA_i (1≤Ai≤100001 \le A_i \le 10000, i=1…Ni=1 \dots N) separated by spaces, where A1A_1 is the value of the first kind of banknote, A2A_2 the value of the second kind, and so on up to ANA_N.

Each of the next MM lines contains two natural numbers XiX_i and CiC_i (1≤Xi≤100001 \le X_i \le 10000, 1≤Ci≤100001 \le C_i \le 10000) separated by a space, where XiX_i is the amount Josip wants to withdraw on his ii-th visit, and CiC_i is the value of the banknote that became smelly on his ii-th visit.

Output

On each of the MM lines, print "DA" if Josip can withdraw exactly XiX_i kuna on his ii-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.

Examples3

  1. Example 1

    Input
    4 2
    2 5 6 1
    11 6
    11 1
    
    Expected output
    DA
    NE
    
  2. Example 2

    Input
    3 3
    7 2 9
    16 7
    16 9
    16 2
    
    Expected output
    DA
    DA
    NE
    
  3. Example 3

    Input
    5 3
    5 2 10 7 6
    13 5
    12 10
    11 7
    
    Expected output
    NE
    DA
    NE