Coin
InterviewTime limit2sMemory limit1024 MB
Find the fewest coins from unlimited denominations whose values sum to V and weights sum to W.
- Level
Medium4 of 10
- Topics
- Dynamic programming
- Solved
- No attempts yet
Problem
A currency is issued in coin denominations. Denomination has a value of cents and a weight of grams (). Two denominations can share the same value or the same weight, but not both.
You are given and . Find , the smallest number of coins whose values add up to exactly cents and whose weights add up to exactly grams. If no such collection of coins exists, is . Every denomination has an unlimited supply of coins.
Input
The first line contains the number of denominations , the target value , and the target weight , separated by spaces.
Each of the next lines contains the value and the weight of one denomination, separated by a space.
, , , , .
Output
Print on a single line. Print when no collection of coins reaches both totals.