A loading dock has several parallel unloading lanes arranged as a grid: m lanes, each currently stocked with exactly n crates of known weights. In one clearing round, a forklift removes exactly one crate from every lane at the same time — specifically the single heaviest crate currently sitting in that lane — so every lane always holds the same number of crates and all lanes become empty together after exactly n rounds. For each round, note the heaviest weight removed across all lanes during that round (i.e. the largest of the m crates taken that round). After all n rounds have happened, report the sum of these n round-heaviest values.
The first line contains two integers m and n — the number of lanes and the number of crates per lane.
Each of the next m lines contains n integers: the weights of the crates currently sitting in that lane.
Print a single integer: the sum of the heaviest weight removed in each of the n clearing rounds.
Example 1
Input
2 3 1 2 4 3 3 1
Expected
8
Explanation
Lane 1 holds crates [1,2,4] and lane 2 holds [3,3,1]. Round 1 removes the heaviest crate from each lane: 4 from lane 1 and 3 from lane 2, so the round-heaviest is max(4,3)=4; lanes become [1,2] and [3,1]. Round 2 removes 2 and 3, round-heaviest max(2,3)=3; lanes become [1] and [1]. Round 3 removes 1 and 1, round-heaviest 1. The total is 4 + 3 + 1 = 8.
Example 2
Input
1 1 10
Expected
10
Explanation
There is a single lane with a single crate weighing 10. The only round removes that crate, so the round-heaviest is 10 and the answer is 10.
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 →