Submit | All submissions | Best solutions | Back to list |
PANCAKES - Delicious Pancakes |
Just as promised, PolyProg will invite you to a bounteous pancake buffet right after this contest. Can you already feel the seductive odours dazing your senses? Well, before your mouth starts watering, you should solve this last problem.
As you might know, the basic ingredients to pancakes are flour, milk and eggs. These may be completed by a passel of additional toppings such as sugar, jam, berries, cheese, ham, mushrooms etc. As the chef of the evening was yet uncertain about the recipe he’d whip up tonight, he asked his assistant simply to buy random quantities of each ingredient.
With these quantities he could make N1 pancakes according to recipe 1, N2 if he decides to follow recipe 2, N3 for recipe 3 and so on and so forth. As the end of the competition is close, the chef will not have enough time to combine several recipes: All pancakes tonight will be of the same taste (too bad :( ). The repertoire of recipes is huge, and as we imagine you to have a ravenous appetite, you are to select the recipe that yields the largest number of pancakes.
Input
The input consists of several test-cases separated by an empty line. The first line of each test-case holds the number of ingredients N (1<=N<=50) the assistant bought followed by the number of recipes R (1<=R<=100) in the chef’s repertoire. Each of the next lines contains exactly N non-negative integers (no larger than 106) informing about the ingredients. The first of these lines lists the quantities the assistant bought of each ingredient. The remaining R lines list the quantities (in the same order as the previous line) necessary to make ten pancakes according to the recipe ri (from 1 to R). The input ends on a test-case having both N and R zero, which must not be processed.
Output
Your program should produce one line per test-case containing the recipe that yields the largest number of pancakes followed by the number of entire pancakes that can be made then. If there is a tie, prefer the recipe that appears first in the input.
SAMPLE INPUT
3 2 20 20 20 5 10 1 2 1 3 6 3 100 60 130 80 100 90 10 5 10 5 10 5 1 2 1 2 20 7 0 0 0 10 30 1 0 0
SAMPLE OUTPUT
2 66 1 100
Added by: | Christian Kauth |
Date: | 2010-09-26 |
Time limit: | 0.200s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All except: ASM64 NODEJS OBJC VB.NET |
hide comments
|
||||||
2011-12-14 21:08:41 _|_
Do remember to multiply with 10 at first only otherwise at later it will give WA........took alot of time |
||||||
2011-12-11 14:55:35 Aditya Muttur
is the number of lines between the test case important. should my outputs also have an empty line between them? |
||||||
2011-09-07 12:17:17 Rachmawan Atmaji Perdana
@Troy : 1 3 |
||||||
2011-07-16 20:17:56 Troy
what shuld be o/p for 1 1 1 3 Should it be 0 0 or 1 3? |
||||||
2011-06-27 16:49:26 Pankaj Jindal
@The champ: your assumption is correct. If there are insufficient ingredients then printing "1 0" gets accepted otherwise gives WA. |
||||||
2011-01-14 16:45:10 shubhang singh chauhan
my code is giving wrong answer but it is giving correct answer on each test case as far as i know . please help.Give me some hard test cases. |
||||||
2010-10-17 19:07:09 The Champ
what if ingredients are not sufficient for any recipe. 3 2 20 20 20 1000 1000 1000 2000 2000 2000 my code gives 1 0 |
||||||
2010-10-17 06:25:00 yogesh
what should be the output for 3 2 20 20 20 0 0 0 0 0 0 @Yogesh No such test cases Last edit: 2010-10-20 02:57:25 |
||||||
2010-10-10 12:29:13 P.B.MUKUND
how is the outcome of second test case equal to hundred???? anyone plz. help... got it thanks... Last edit: 2010-10-10 12:49:04 |
||||||
2010-10-01 20:49:53 Amit
@Christian What is the problem in my code....??? I dont get it..... @Black-Out You solve the problem in two almost identical steps. But what happens if in the first step two recipes score equal (i.e. m2=m1)? It's too early to decide which recipe is better, as this will turn out during your second step. But you decide that the first one appearing is better (if (m2>m1)), which unfortunately isn't always the case ;) My suggestion: Multiply your ar[] immediately by 10 and get rid of the second step. Last edit: 2010-10-01 22:07:26 |