Loading...
Loading...
Loading...
In a college quiz each team has a row of scores, one per round. Print the rows ordered by the team's total score, from lowest to highest. If two teams have the same total, the team listed earlier comes first.
Example 1
Input
3 3 5 5 5 1 2 3 9 0 0
Output
1 2 3 9 0 0 5 5 5
Totals are 15, 6 and 9.
Example 2
Input
3 2 4 4 10 -2 1 7
Output
4 4 10 -2 1 7
All three total 8, so the original order stays.
Try the problem first. Open one hint at a time.
Work out each row's total once and store it in a long[] total.
Sort the row indexes, not the numbers: make int[] order = {0, 1, …, r-1} and sort it by total.
Insertion sort that only moves an index past strictly larger totals keeps tied teams in their original order.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor