Yet Another Coin Problem
Time limit2sMemory limit1024 MB
Given N coin types with counts and values, decide whether some choice of coins sums to exactly X, and print the number of each coin type used if so.
- Level
Hard8 of 10
- Topics
- Dynamic programming, Number theory
- Solved
- No attempts yet
Problem
There are kinds of coins. The -th kind has coins, and each coin is worth won. Can you choose some coins so that their values sum to exactly won? If it is possible, print one way to do it.
Input
The first line contains the number of test cases .
The first line of each test case contains and , separated by a space.
Each of the next lines contains and , separated by a space. Within one test case, all are distinct.
The sum of over all test cases does not exceed , and the sum of all does not exceed .
Output
For each test case, print YES if you can choose coins so that their values sum to exactly won, and NO otherwise. If you print YES, print a second line with integers separated by spaces. They must satisfy the following conditions.