#P10973. Coins
Coins
Problem Description
People in Silverland use coins. They have coins with denominations . One day, Tony opened his piggy bank and found some coins inside. He decided to go to a nearby shop to buy a very nice watch. He wants to pay the exact price (no change), and he knows the price of the watch will not exceed . However, he does not know the exact price of the watch.
You need to write a program that reads , , , and the corresponding counts (which means how many coins of each denomination Tony has), and then computes how many prices Tony can pay using these coins (all prices from to ).
Input Format
The input contains multiple test cases (no more than cases). The first line of each test case contains two integers and . The second line contains integers, which represent and . The last test case ends with two zeros.
Output Format
For each test case, output the answer on a separate line.
3 10
1 2 4 2 1 1
2 5
1 4 2 1
0 0
8
4
Hint
Translated by ChatGPT 5