Back
Close

Sailing regatta - simplified results

Statement

 Goal

Sailing works on a 'low point scoring system', your challenge is to compute the winning final score from a number of boats entered in a regatta.

Results
A race winner gets a result of 1 point, second place 2 points and working downwards for the other race finishers.

When a boat does not finish a race it receives a result equal to the number of boats entered B plus one. For this simplified version of the rules, these boats will have a result of RET. However, if a boat is caught by the race jury they are disqualified with a result that appears as DNE. This penalty result is always included in their final score.

If a result is RET or DNE then that boat's result is 1 point more than the number of boats, B entered. B+1

The boat's final score is the sum of the boat's race results. A discard of their worst result is allowed when more than 5 races are sailed.

Discarding worst result when 5 or more races are sailed
The boats worst result is subtracted provided it is not DNE. The total sum of their remaining results is the boat's final score.

Deciding the winner
A boat wins the regatta if they have the lowest final score.

If there is a tie on final scores then the winner is decided by sorting the results from best to worst. The results are compared and at the point where there is a difference, the winner is the one whose result is lowest.

If a tie still exists, then the best result in the last race decides the winner.

Output
You will be presented with a number of boats B entered in a number of races N with their race results. You should deliver the name of the race winner space separated with their winning final score.

Example of where boats tie on final scores after worst race is discarded (N >= 5):
Boat_A 1 2 3 4 5
total, 15 - 5 = 10 tied on points, reorder 1 2 3 4 5 so Boat_A wins (5 < 6)
Boat_B 2 3 4 6 1
total, 16 - 6 = 10 tied on points, reorder 1 2 3 4 6


Example of a tie broken on last race: (N < 5, with 2 boats entered so RET, DNE = 3 )
Boat_A 1 2 3 DNE
total, 1+2+3+3 = 9 reorder 1 2 3 DNE
Boat_B 3 1 RET 2
total, 2+3+1+3 = 9 reorder 1 2 3 RET same final scores, so in last race Boat_B wins (2 < DNE)
Input
Line 1: An integer B for the number of boats competing.
Line 2: An integer N for the number of races.
Next B Lines: Boat's name followed by N 'space' separated race results.
Output
Line 1: The name of the winning boat space separated to the boat's winning final score.
Constraints
2 ≤ B ≤ 10
1 ≤ N ≤ 10
1≤ NAME ≤ 20
Example
Input
3
3
lady_jane 1 2 3
skylark 3 1 1
chomper 2 3 2
Output
skylark 5

Tags
SortingLoopsLogicParsing

Difficulty
Easy

Test cases
3x3 mini series Test
Input
3 3 lady_jane 1 2 3 skylark 3 1 1 chomper 2 3 2
Output
skylark 5

Validator 1 Validator
Input
3 3 fishy_times 2 3 1 buzzby 1 2 2 flipper_tripper 3 1 3
Output
buzzby 5

Boat on boat Test
Input
2 1 one 1 two 2
Output
one 1

Validator 2 Validator
Input
2 1 a 2 b 1
Output
b 1

Easy 'tide' Test
Input
7 4 flash RET RET 5 RET jack'n'jill 1 2 3 3 cookie_monster 5 1 1 2 raggamuffin 6 6 5 RET x-ray 3 3 2 1 delta 2 4 4 4 snoopy 4 7 RET RET
Output
cookie_monster 9

Validator 3 Validator
Input
4 4 alpha RET 4 RET RET bravo 1 2 RET RET charlie 3 3 1 1 delta 2 2 2 2
Output
charlie 8

Big Series needs a discard Test
Input
7 6 unaone 1 5 4 RET 6 7 bissotwo 2 3 2 1 7 1 terrathree 3 2 1 3 5 2 cartefower 6 6 5 RET 3 3 pentafive 7 1 3 2 4 4 soxisix 4 4 RET 4 1 5 setteseven 5 7 RET RET 2 6
Output
bissotwo 9

Validator 4 Validator
Input
4 10 unaone 1 RET 1 3 1 2 3 RET 4 2 bissotoo 2 1 2 1 2 3 RET 1 2 4 oktaeight 3 3 RET 2 3 1 2 2 1 1 noveniner 4 2 3 RET 4 4 1 3 3 3
Output
bissotoo 18

Naughty Sailors tie on points Test
Input
5 6 badboy DNE 1 RET RET RET RET badgirl RET RET 1 RET RET DNE earlystart RET DNE RET 1 RET RET rule42er RET DNE RET RET 1 RET tortoise RET RET DNE RET RET 1
Output
tortoise 25

Validator 5 Validator
Input
5 5 badboy DNE 1 RET RET RET badgirl RET RET 1 RET DNE earlystart RET RET 1 DNE RET rule42er RET DNE RET 1 RET slowcoach RET DNE RET RET 1
Output
slowcoach 19

Solution language

Solution

Stub generator input