A yacht club runs a season-long regatta in which m boats compete across n legs. After every leg, officials record each boat's whole-number point total for that leg on a scoreboard: one row per boat, one column per leg. Before publishing the results, the race committee wants the scoreboard reprinted so the boats appear from the highest score to the lowest score on one particular leg, while each boat's entire row of per-leg scores stays intact and moves together as a single block — only the row order changes, never the values inside a row.
m, n, and k — the number of boats, the number of legs, and the (0-indexed) leg to rank by.m lines contains n integers, the j-th of which is the score the boat earned on leg j.Print m lines. The i-th line must contain the n scores of whichever boat ranks i-th when all boats are ordered by non-increasing score on leg k. Every printed row must reproduce one of the input rows exactly, in full, with only the row order changed.
k are pairwise distinct across all boats, so the ranking on leg k is never tied.Example 1
Input
3 3 0 6 7 8 3 5 9 5 8 4
Expected
6 7 8 5 8 4 3 5 9
Explanation
Column 0 holds the scores 6, 3, and 5 for the three boats. Sorted from highest to lowest that is 6, 5, 3, so the boat with row [6,7,8] is printed first, then [5,8,4], then [3,5,9]; each row is reproduced unchanged, only the order among rows changes.
Example 2
Input
2 2 1 3 1 2 3
Expected
2 3 3 1
Explanation
Column 1 (the second leg, 0-indexed) holds the scores 1 and 3. Sorted from highest to lowest that is 3 then 1, so the boat with row [2,3] (leg-1 score 3) is printed first, followed by [3,1] (leg-1 score 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 →