#P3423. Minimum Coins with Limited Quantities

    ID: 16678 Type: Default 1000ms 256MiB

Minimum Coins with Limited Quantities

Minimum Coins with Limited Quantities

In the Byteotian Bit Bank (BBB) system, there are $$n$$ types of coins with values $$b_1, b_2, \ldots, b_n$$. However, each coin type is available in limited quantity. Given a target value $$k$$, your task is to determine the minimum number of coins required to form exactly $$k$$. It is guaranteed that the value $$k$$ can be achieved using the available coins.

Note: The input provides the number of coin types, the target value, the list of coin denominations, and the quantity available for each coin type.

inputFormat

The input is given in the following format:

n k
b1 b2 ... bn
c1 c2 ... cn

Where:

  • n: the number of coin types.
  • k: the target value to be formed.
  • bi: the value of the i-th type of coin.
  • ci: the available quantity of the i-th coin.

outputFormat

Output a single integer, which is the minimum number of coins required to form the value $$k$$.

sample

3 11
1 5 7
5 2 1
3