## MWC '15 #3 P2: Mechanical Pencils

View as PDF

Points: 5 (partial)
Time limit: 2.0s
Memory limit: 256M

Author:
Problem type

lim495062 has recently become obsessed with mechanical pencils. He has mechanical pencils (numbered to ) and packs of graphite lead (numbered to ).

As 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.

lim495062 purchased his lead packs from very questionable sources. As a result, there may be different amounts of lead () and the lead may have different lengths .

Now lim495062 wants to know which pencil and lead pack combination give him the longest 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.

• commented on April 4, 2016, 2:38 p.m.

Can we have a proper input/output specification, with an explanation, because currently it leaves a lot up to question.

• commented on April 4, 2016, 10:42 a.m.
2 2
40
30
2 20 10
1 1
• commented on April 4, 2016, 4:35 p.m.

The output should be 2 2

• commented on April 4, 2016, 8:07 a.m.

Thank

• commented on April 4, 2016, 4:43 p.m.