#P7166. Tennis Tournament Scheduling
Tennis Tournament Scheduling
Tennis Tournament Scheduling
You are the organizer of a tennis tournament with \(n\) players numbered from 1 to \(n\). Before the tournament, you tested their initial rankings on three different court surfaces: A, B, and C. In the tournament each pair of players plays exactly one match (i.e. a total of \(\frac{n(n-1)}{2}\) matches).
There are no draws. In a match played on surface \(S\) (where \(S\) can be A, B, or C), the player with the better (i.e. lower) pre-tournament ranking on surface \(S\) wins. However, you have a hidden agenda: you wish the winner to play on his best surface – that is, the surface on which his initial ranking is the highest (lowest ranking value). Formally, for each player \(p\), define his preferred surface as the one for which his ranking is minimum. (If there is a tie, the tie is broken in the order A \(<\) B \(<\) C.)
For each match between players \(i\) and \(j\), you can choose one surface \(S\) among \(\{A, B, C\}\) under the following rule:
- Simulate the match on surface \(S\): the winner is the player with the lower ranking on \(S\) and the other is the loser.
- If the winner's preferred surface is \(S\), then this surface is eligible.
- If more than one surface is eligible, choose the one where the loser's ranking on that surface is smallest (i.e. the loser is relatively stronger on that surface). If there is still a tie, choose the surface with the smallest label (A \(<\) B \(<\) C).
- If no surface is eligible, then choose from all three surfaces using the same tie-breaking rule (i.e. choose the surface under which the loser's ranking is the smallest, breaking ties by A \(<\) B \(<\) C).
Your task is to determine two things:
- The number of matches held on each surface (in the order A, B, C).
- For each player, the total number of matches they won.
Input:
The first line contains an integer \(n\) (the number of players). The next three lines each contain \(n\) space-separated integers. The first of these lines gives the rankings for surface A, the second for surface B, and the third for surface C. The \(i\)th integer on a line corresponds to the initial ranking of player \(i\) on that surface. Lower numbers indicate better ranking.
Output:
On the first line, output three integers representing the number of matches played on surfaces A, B, and C, respectively. On the second line, output \(n\) integers where the \(i\)th integer is the number of matches won by player \(i\).
inputFormat
The input begins with an integer \(n\) (\(2 \le n \le 1000\), for example). Following this, there are three lines, each containing \(n\) space-separated integers. The first line is the ranking for surface A, the second for surface B, and the third for surface C.
outputFormat
Output two lines. The first line contains three integers representing the number of matches held on surfaces A, B, and C respectively. The second line contains \(n\) integers, where the \(i\)th integer indicates the number of matches won by player \(i\).
sample
3
1 2 3
2 3 1
3 1 2
1 1 1
1 1 1
</p>