A logistics dispatcher tracks a fleet of cargo ships preparing to leave port. Every ship in the fleet has the same fixed number of cargo holds, and each hold has a recorded weight in tonnes. Before departure, the dispatcher wants to flag the single ship that is carrying the heaviest total load, so it can be checked for overloading. Given the hold weights for every ship, report the largest total load carried by any one ship.
The first line contains two integers n and m — the number of ships in the fleet and the number of cargo holds on each ship. Each of the next n lines contains m integers, the weights of that ship's cargo holds in order.
Print a single integer: the maximum total weight carried by any single ship, where a ship's total weight is the sum of its cargo-hold weights.
1 <= n, m <= 50 1 <= weight <= 100 for every cargo-hold weight
Example 1
Input
2 3 1 2 3 3 2 1
Expected
6
Explanation
Ship 1 carries 1+2+3 = 6 tonnes and ship 2 carries 3+2+1 = 6 tonnes. Both totals are 6, so the maximum total load in the fleet is 6.
Example 2
Input
3 2 1 5 7 3 3 5
Expected
10
Explanation
The three ships carry totals of 1+5=6, 7+3=10, and 3+5=8 tonnes respectively. The largest of these totals is 10, so 10 is printed.
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 →