The Perfect Chocolate CandyProblem code: CANDY |
All submissions for this problem are available.
The chef is a fan of candies with chocolate and caramel, and has devoted much of his life to finding the perfect ratio of chocolate to caramel. He recently discovered the perfect ratio, but to his dismay, none of his favourite candy shoppes sell candies with exactly that ratio. So the chef crafted a plan to buy several candies, and melt them together into a larger candy so that the resulting candy will have the perfect ratio. How many candies will he have to buy? The chef may buy multiple candies of the same type.
Input:
Input begins with an integer N, the number of different candies available at the various shoppes. N lines follow, each containing 2 integers Chocolatei and Carameli indicating the grams of chocolate and caramel, respectively, contained in the (i)th candy. Finally, there is a line containing 2 integers desiredChocolate and desiredCaramel, indicating the chef's desired ratio of chocolate to caramel.
Output:
For each test case, output on a single line the minimum number of candies the chef will have to buy. If it is impossible to produce a candy with the desired ratio, output -1 instead.
Example
Input 1:
3 4 5 2 4 4 1 1 1
Output 1:
3
In this example, the chef purchases one of each candy and combines them to form a candy with 8 grams chocolate and 8 grams caramel.
Input 2:
3 2 3 4 6 10 15 5 8
Output 2:
-1
Constraints:
1 ≤ N ≤ 15
1 ≤ Chocolatei ≤ 500
1 ≤ Carameli ≤ 500
1 ≤ desiredChocolate ≤ 500
1 ≤ desiredCaramel ≤ 500
For all candies, Chocolatei/Carameli ≠ desiredChocolate/desiredCaramel
No two candies will be identical.
| Date: | 2010-09-25 |
| Time limit: | 3s |
| Source limit: | 50000B |
| Languages: | All except: TCL |
Comments
Loading Comments...
SUCCESSFUL SUBMISSIONS FOR THIS PROBLEM:
Loading Submissions...RECENT ACTIVITY FOR THIS PROBLEM:
Loading Recent Activity...HELP
Program should read from standard input and write to standard output.
After you submit a solution you can see your results by clicking on the [My Submissions] tab on the problem page. Below are the possible results:
- Accepted
Your program ran successfully and gave a correct answer. If there is a score for the problem, this will be displayed in parenthesis next to the checkmark. - Time Limit Exceeded
Your program was compiled successfully, but it didn't stop before time limit. Try optimizing your approach. - Wrong Answer
Your program compiled and ran succesfully but the output did not match the expected output. - Runtime Error
Your code compiled and ran but encountered an error. The most common reasons are using too much memory or dividing by zero. For the specific error codes see the help section. - Compilation Error
Your code was unable to compile. When you see this icon, click on it for more information.
If you are still having problems, see a sample solution here.
