# Minimum Cost To Buy Oranges

Last Updated: 21 Jul, 2020
Difficulty: Moderate

## PROBLEM STATEMENT

#### You are required to find the minimum total cost to buy exactly 'W' kg oranges and if it's not possible to buy precisely W kg oranges then print -1. There is an infinite supply of all available packet types.

##### Note :
``````Array index 'i' denotes the cost of (i+1)kg packet.
Example: cost[0] is the cost of a 1kg packet of oranges.
``````
##### Input Format :
``````The first line of each test case contains two single space-separated integers 'N' and 'W' where 'N' denotes the size of the array/list(cost), and 'W' is the bag's size.

The second line of each test case contains 'N' single space-separated integers denoting the values of the cost.
``````
##### Output Format :
``````Print the minimum cost to buy exactly W kg oranges. If it's impossible, print "-1".
``````
##### Note :
``````You are not required to print anything, it has already been taken care of. Just implement the function.
``````
##### Constraints :
``````1 <= N <= 1000
1 <= W <= 1000
-1 <= cost[i] <= 1000000

Time Limit: 1sec
``````