mechanical pencils (numbered to ) and packs of graphite lead (numbered to ).
has recently become obsessed with mechanical pencils. He hasAs you may know, a whole piece of lead can never be used up completely. It can be used up to a certain length, until the mechanical pencil loses grip of the lead, at which point the lead then must be discarded. The maximum length at which the lead may not be used by the mechanical pencil is and may vary from pencil to pencil.
() and the lead may have different lengths .
purchased his lead packs from very questionable sources. As a result, there may be different amounts of leadNow
wants to know which pencil and lead pack pair permits the maximum writing time. Total usable lead positively correlates with writing time, meaning the more usable lead he has, the longer he can write for.Input Specification
The first line contains two space separated integers and , the number of mechanical pencils and the number of lead packs respectively.
The next lines contain integers , the value of pencil .
The next lines initiate with integer denoting the number of lead this pack has, followed by integers denoting the size, , of the piece of lead.
Output Specification
Two space separated integers, the pencil and lead pack pair that permits the maximum writing time.
If two pencils are tied, then take the one theoretically better pencil, meaning the one that would allow more lead use on average if used on all possible sets of lead packs. If still tied, take the first one (the one with the lower index). If two lead packs are tied, then take the one with fewer pieces of lead. If they have the same amount of lead, take the first one.
Sample Input
2 2
2
4
4 1 2 2 1
1 4
Sample Output
1 2
Explanation of Sample Output
It is optimal to use pencil 1 with lead pack 2 for a maximum lead use of 2. All other combinations permit 0 lead use.
Comments
Can we have a proper input/output specification, with an explanation, because currently it leaves a lot up to question.
The output should be
2 2