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 10 grams chocolate and 10 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.
| Author: | pieguy |
| Date Added: | 25-09-2010 |
| Time Limit: | 3 sec |
| Source Limit: | 50000 Bytes |
| Languages: | ADA, ASM, BASH, BF, C, C99 strict, CAML, CLOJ, CLPS, CPP 4.0.0-8, CPP 4.3.2, CS2, D, ERL, F#, FORT, GO, HASK, ICK, ICON, JAR, JAVA, JS, LISP clisp, LISP sbcl, LUA, NEM, NICE, PAS fpc, PAS gpc, PERL, PERL6, PHP, PIKE, PRLG, PYTH, PYTH 3.1.2, RUBY, SCALA, SCM guile, SCM qobi, ST, TEXT, WSPC |
Comments
SUCCESSFUL SUBMISSIONS FOR THIS PROBLEM:
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.

Fetching successful submissions

can anyone please suggest few
can anyone please suggest few more test case
to admin: please give me few more test cases, my algo is fyn but dont know y giving wrong answer on submission.
y in all the solutions
y in all the solutions everyone is using 500000 250000 size...
i can only see that max limit is 15,500 ,, thats not big???
my bad.. i got it
my bad.. i got it