A chain of three trailhead gear depots, numbered 1, 2, and 3, each stock a subset of hiking items at their own price. The stockroom hands you a flat list of price listings and asks you to build a price board: one row per item showing its price at every depot, with a placeholder for depots that don't carry it.
Line 1 contains an integer N — the number of listings.
Each of the next N lines contains three integers item_id, depot_id, and price, where depot_id is 1, 2, or 3. Each (item_id, depot_id) pair appears in at most one listing.
For each distinct item_id that appears in at least one listing, in ascending order of item_id, print one line: item_id price1 price2 price3, where price_k is the price of that item at depot k, or -1 if depot k has no listing for that item. Separate the four numbers with single spaces.
Example 1
Input
4 10 1 100 10 2 120 20 1 50 20 3 55
Expected
10 100 120 -1 20 50 -1 55
Explanation
Item 10 is stocked at depot 1 (100) and depot 2 (120) but not depot 3, giving '10 100 120 -1'. Item 20 is stocked at depot 1 (50) and depot 3 (55) but not depot 2, giving '20 50 -1 55'. Item 10 is printed before item 20 since 10 < 20.
Example 2
Input
1 30 2 75
Expected
30 -1 75 -1
Explanation
Item 30 has a single listing at depot 2, price 75, and no listings at depot 1 or depot 3, giving '30 -1 75 -1'.
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 →