Zombie Swallows
Time limit1sMemory limit128 MB
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 micrograms and at most its stomach capacity of 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 and , inclusive. (The empty subset, with total weight , is allowed.)
Input
The first line contains (), the number of swallows that need to feed. Each of the next lines contains the feeding information for one swallow:
- Two integers and (): the swallow's minimum energy requirement and maximum stomach capacity, in micrograms.
- An integer (): the number of insects the swallow may choose from.
- Then integers: the weight of each insect in micrograms, each a positive integer not exceeding .
Because of the nature of zombie swallows, 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.