Bank Notes
Time limit3sMemory limit128 MB
With bounded supplies of each note denomination, find the fewest notes that sum exactly to k.
- Level
Medium7 of 10
- Topics
- Dynamic programming, Greedy
- Solved
- No attempts yet
Problem
A bank in Byteotia runs the largest network of cash dispensers in the country. The bank wants every dispenser to pay out any requested amount using as few banknotes as possible.
The banknote denominations in circulation are . Each dispenser holds notes of denomination .
Given, on standard input, the dispenser's stock of notes and the amount to be paid, write a program that determines the minimal total number of banknotes needed to pay the amount exactly.
Input
The first line contains the number of denominations ().
The second line contains integers separated by single spaces ().
The third line contains integers separated by single spaces (); is the number of notes of denomination left in the dispenser.
The fourth line contains the amount to be paid (). It is guaranteed that can be paid exactly with the available notes.
Output
Output a single integer: the minimal total number of banknotes needed to pay the amount exactly.