#P8342. [COCI 2021/2022 #6] Med

[COCI 2021/2022 #6] Med

Problem 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 66 rounds, and in each round the score is between 00 and 500500 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 COCB\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(1n500)n(1≤n≤500), the number of beekeepers.

The next nn lines each contain a beekeeper name si(1si10)s_i(1 ≤|s_i|≤10) and 55 numbers b1b5b_1\cdots b_5, representing the score of the ii-th beekeeper in the first 55 rounds.

Output Format

Output nn lines.

On the ii-th line, output the best possible rank and the worst possible rank for the ii-th beekeeper.

3
pavel 120 200 300 400 500
keko 150 400 300 200 100
bartol 470 120 90 93 189
1 2
1 3
2 3
2
ante 275 275 275 275 275
mate 25 100 175 250 325
1 1
2 2

Hint

Sample 2: so far, ante\rm{ante} has 13751375 points and mate\rm{mate} has 875875 points. If mate\rm{mate} gets 500500 points in the last round and ante\rm{ante} gets 00 points, then the final result is a tie and they both have 13751375 points. However, since the ranking uses lexicographical order, ante\rm{ante} is smaller than mate\rm{mate}, so ante\rm{ante} will still be ranked ahead.

Constraints:

For 20%20\% of the testdata: 1n21\le n\le2.

For 100%100\% of the testdata: 1n5001\le n\le500, 1si101\le |s_i|\le10 (it is guaranteed that everyone’s name is unique), 1bi5001\le b_i \le500.

The score setting of this problem is the same as COCI 2021-2022#6, with a full score of 5050 points.

Translated by ChatGPT 5