Back
Close

Reorder Terms

Statement

 Goal

You are given n rows with three terms per line separated by a space.
a1 b1 c1
a2 b2 c2
...
an bn cn

Reorder these rows from lowest value to highest value. Calculate the value of these rows using Value = a*b + c. The test cases will be written such that there are no ties.

Example:
3 2 1
1 1 1
-1 0 5

3 2 1 = 3*2 + 1 =7
1 1 1 = 1*1 + 1 = 2
-1 0 5 = -1*0 +5 = 5

Result:
1 1 1
-1 0 5
3 2 1
Input
n number of rows
Output
Reordered rows
Constraints
1 < n <= 6
-128 <= a,b,c < 128
Example
Input
3
3 2 1
1 1 1
-1 0 5
Output
1 1 1
-1 0 5
3 2 1

Game modes
Fastest, Shortest

Test cases
Test 1 Test
Input
3 3 2 1 1 1 1 -1 0 5
Output
1 1 1 -1 0 5 3 2 1

Validator 1 Validator
Input
3 5 6 1 1 1 1 -2 0 3
Output
1 1 1 -2 0 3 5 6 1

Test 2 Test
Input
4 -1 -2 3 -2 5 1 3 -6 18 4 4 100
Output
-2 5 1 3 -6 18 -1 -2 3 4 4 100

Validator 2 Validator
Input
4 -1 -3 5 -2 6 1 -4 5 20 6 6 16
Output
-2 6 1 -4 5 20 -1 -3 5 6 6 16

Test 3 Test
Input
6 100 -1 -5 -1 0 1 0 0 3 2 4 6 0 5 2 -1 -1 -1
Output
100 -1 -5 -1 -1 -1 -1 0 1 0 5 2 0 0 3 2 4 6

Validator 3 Validator
Input
6 90 -1 -4 -2 0 2 0 0 5 3 4 8 0 5 3 -1 -1 -1
Output
90 -1 -4 -1 -1 -1 -2 0 2 0 5 3 0 0 5 3 4 8

Test 4 Test
Input
3 -128 -128 2 -128 127 0 0 0 127
Output
-128 127 0 0 0 127 -128 -128 2

Validator 4 Validator
Input
3 127 127 -2 -128 127 -128 0 1 127
Output
-128 127 -128 0 1 127 127 127 -2

Test 5 Test
Input
4 0 0 1 0 0 3 0 0 2 0 0 4
Output
0 0 1 0 0 2 0 0 3 0 0 4

Validator 5 Validator
Input
4 0 1 11 0 1 13 0 1 12 0 1 14
Output
0 1 11 0 1 12 0 1 13 0 1 14

Solution language

Solution

Stub generator input