A regional delivery hub keeps two separate logs each day: one filled in by the morning shift and one filled in by the evening shift. Each log lists, for every route run that shift completed, the driver's ID and the number of packages delivered on that run, in the order the runs were completed. At the end of the day, dispatch wants a single consolidated log formed by taking every morning entry first (kept in its original order) and then every evening entry (also kept in its original order), with every row renumbered starting at 1.
n1, the number of entries in the morning log.n1 lines contains two space-separated integers driverId and packages — one morning-log entry, in log order.n2, the number of entries in the evening log.n2 lines contains two space-separated integers driverId and packages — one evening-log entry, in log order.Print n1 + n2 lines. The first n1 lines are the morning entries in their original order, and the remaining n2 lines are the evening entries in their original order; each line has the form index driverId packages, where index starts at 1 for the first printed line and increases by 1 for each subsequent line. If both logs are empty, print nothing.
Example 1
Input
3 11 5 12 0 11 8 2 13 3 11 2
Expected
1 11 5 2 12 0 3 11 8 4 13 3 5 11 2
Explanation
The morning log has 3 entries (driver 11 with 5 packages, driver 12 with 0, driver 11 again with 8) and the evening log has 2 entries (driver 13 with 3, driver 11 with 2). The consolidated log keeps the morning rows first in order as rows 1-3, then appends the evening rows as rows 4-5. Driver 11 appears three times across the two logs, and each occurrence is kept as its own row.
Example 2
Input
0 2 20 4 21 1
Expected
1 20 4 2 21 1
Explanation
The morning log is empty (n1 = 0), so the consolidated log is simply the evening log renumbered starting at 1: row 1 is driver 20 with 4 packages, and row 2 is driver 21 with 1 package.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →