Back
Close
  • 147

Learning Opportunities

This puzzle can be solved using the following concepts. Practice using these concepts and improve your skills.

Statement

 Goal

You live in a world where all coins have the same shape, weight and feel. You can't distinguish them in your pocket. Knowing how many coins of each value you have in your pocket, how many should you grab, without looking, to be sure to have enough money to pay?
Input
Line 1 : An integer valueToReach representing the price you want to be able to pay
Line 2 : An integer N representing the number of different coin types you have
Line 3 : N integers separated by space representing the number of coins of each type
Line 4 : N integers separated by space representing the value of each type
Output
Line 1 : A line containing a single integer representing the minimum number of coins you need to grab to be sure to have enough money to pay. -1 if there's not enough money in your pocket
Constraints
1<= number of coins <=1000
1<= coin values <=1000
1<= N <=1000
Example
Input
8
1
5
6
Output
2

A higher resolution is required to access the IDE