Zombie Swallows

Time limit1sMemory limit128 MB

Summary
For each of up to 30 swallows, decide whether some subset of up to 150 insect weights sums to a value in the range [Cmin, Cmax].
Level

Hard8 of 10

Topics
Dynamic programming, Bit manipulation, Math, Brute force
Solved
No attempts yet

Problem

In the movie Monty Python and the Holy Grail, a crucial scene revolves around the question, “What is the airspeed velocity of an unladen swallow?” For an undead ornithologist, perhaps the more important question is, “What is the swallowing capacity of a zombie swallow?”

To control a zombie swallow, you must control what it swallows. A zombie swallow that has just risen from its grave has an empty stomach, so you must feed it immediately. Each zombie swallow must swallow enough insects to meet its minimum energy requirement, but no more than its stomach can hold. In other words, given a set of insects to feed on, the swallow picks a subset whose total weight is at least its minimum requirement of CminC_{min} micrograms and at most its stomach capacity of CmaxC_{max} micrograms. If such a subset exists, the swallow survives.

For each swallow, decide whether it is possible to choose a subset of the available insects whose total weight lies between CminC_{min} and CmaxC_{max}, inclusive. (The empty subset, with total weight 00, is allowed.)

Input

The first line contains SS (S≤30S \le 30), the number of swallows that need to feed. Each of the next SS lines contains the feeding information for one swallow:

  • Two integers CminC_{min} and CmaxC_{max} (0≤Cmin<Cmax≤2260 \le C_{min} < C_{max} \le 2^{26}): the swallow's minimum energy requirement and maximum stomach capacity, in micrograms.
  • An integer nn (0≤n≤1500 \le n \le 150): the number of insects the swallow may choose from.
  • Then nn integers: the weight of each insect in micrograms, each a positive integer not exceeding 2262^{26}.

Because of the nature of zombie swallows, 1≤CmaxCmax−Cmin≤600001 \le \dfrac{C_{max}}{C_{max} - C_{min}} \le 60000 always holds.

Output

For each swallow, print Sallow swallow swallows. if its feeding requirements can be met. Otherwise, if no combination of insects satisfies the requirements (the swallow would be underfed or overfed no matter what it chooses), print Sallow swallow wallows in dust. Print the answers in the same order as the input.

Examples3

  1. Example 1

    Input
    2
    8 11 2 3 5
    299 300 9 1 2 3 4 5 60 130 260 270
    
    Expected output
    Sallow swallow swallows.
    Sallow swallow wallows in dust.
    
  2. Example 2

    Input
    3
    1 2 3 1 1 1
    10 12 4 5 5 5 5
    13 14 3 5 5 5
    
    Expected output
    Sallow swallow swallows.
    Sallow swallow swallows.
    Sallow swallow wallows in dust.
    
  3. Example 3

    Input
    2
    11 12 1 12
    11 12 1 10
    
    Expected output
    Sallow swallow swallows.
    Sallow swallow wallows in dust.