P8342 [COCI 2021/2022 #6] Med

Description

Today is the last round of the Open Competition. People know that the two contests use the same scoring system. More precisely, both contests have $6$ rounds, and in each round the score is between $0$ and $500$ points. The scores from all rounds are added up to form the total score used for the final ranking. After all six rounds finish, contestants are ranked by total score. If two contestants have the same score, then the one with the lexicographically smaller name is ranked before the one with the lexicographically larger name. No two contestants have the same name. The beekeepers are very impatient, and they want to know their final ranking in advance. Each beekeeper wants to know the best and worst position they can possibly end up with in the final ranking. As programmers for the $\rm{COCB}$ contest, they ask you to tell them what rank they could occupy after the sixth round.

Input Format

The first line contains a positive integer $n(1≤n≤500)$, the number of beekeepers. The next $n$ lines each contain a beekeeper name $s_i(1 ≤|s_i|≤10)$ and $5$ numbers $b_1\cdots b_5$, representing the score of the $i$-th beekeeper in the first $5$ rounds.

Output Format

Output $n$ lines. On the $i$-th line, output the best possible rank and the worst possible rank for the $i$-th beekeeper.

Explanation/Hint

Sample 2: so far, $\rm{ante}$ has $1375$ points and $\rm{mate}$ has $875$ points. If $\rm{mate}$ gets $500$ points in the last round and $\rm{ante}$ gets $0$ points, then the final result is a tie and they both have $1375$ points. However, since the ranking uses lexicographical order, $\rm{ante}$ is smaller than $\rm{mate}$, so $\rm{ante}$ will still be ranked ahead. ### Constraints: For $20\%$ of the testdata: $1\le n\le2$. For $100\%$ of the testdata: $1\le n\le500$, $1\le |s_i|\le10$ (it is guaranteed that everyone’s name is unique), $1\le b_i \le500$. ##### The score setting of this problem is the same as [COCI 2021-2022#6](https://hsin.hr/coci/contest6_tasks.pdf), with a full score of $50$ points. Translated by ChatGPT 5