#K63262. Racing Tournament Final Positions
Racing Tournament Final Positions
Racing Tournament Final Positions
You are given n cars that participate in m races. In each race, the cars finish in a particular order represented as a permutation of the numbers from 1 to n. The finishing position of a car in a race is its rank (1-indexed). The average ranking of a car is computed as \(\frac{\text{total rank}}{m}\), where the total rank is the sum of the car's positions in all races.
The final positions are determined as follows:
- Sort the cars by their average ranking in ascending order (lower value is better).
- If multiple cars have the same average ranking (i.e. the difference between averages is zero, considering precision), they share the same final position.
- The positions are assigned starting from 1, and if a tie occurs, the next distinct ranking position is increased by the number of cars sharing the previous position.
For example, if the computed average rankings lead to final positions [1, 1, 3], then the first two cars share position 1 and the third car is in position 3.
inputFormat
The first line contains two integers n and m representing the number of cars and the number of races, respectively.
The next m lines each contain n space-separated integers. Each line represents one race where the i-th integer is the finishing order label for car i.
outputFormat
Output a single line with n space-separated integers. The i-th integer is the final position of car i after considering all the races.
## sample3 2
1 2 3
2 1 3
1 1 3