P1786 Contribution Sorting
Background
> Guild name: Xingyue Homeland.
>
> Guild leader’s honorific: Dragonfly Kang.
>
> Guild ID: 2685023.
>
> Guild level: 4.
>
> Guild members: 101/110.
>
> Guild skills: (?).
Profile of “Xingyue Homeland.” All friends are welcome to join ^\_^.
---
There are many inactive accounts in absi2011’s guild. Now absi2011 and the guild leader have decided to remove some inactive accounts, add some new members, and also encourage members with high contribution, giving the guild a thorough reorganization.
Source: fight.pet.qq.com. Problem authorized by absi2011.
Description
At present, the guild can have at most:
- $1$ guild leader ($\texttt{BangZhu}$).
- $2$ vice leaders ($\texttt{FuBangZhu}$).
- $2$ guardians ($\texttt{HuFa}$).
- $4$ elders ($\texttt{ZhangLao}$).
- $7$ hall masters ($\texttt{TangZhu}$).
- $25$ elites ($\texttt{JingYing}$).
- Any number of regular members ($\texttt{BangZhong}$).
The above positions are listed from highest to lowest.
Now absi2011 is going to adjust almost everyone’s position in the guild. He finds this difficult, so he asks you to help.
He gives you, for each person:
- Name.
- Original position.
- Contribution.
- Level.
He wants to sort everyone in the guild except the guild leader and vice leaders by the following keys:
- Contribution (descending), primary key.
- Order of appearance in the input (from earlier to later), secondary key.
Then update these people’s positions as follows:
- Ranks $1$ to $2$: $\texttt{HuFa}$.
- Ranks $3$ to $6$: $\texttt{ZhangLao}$.
- Ranks $7$ to $13$: $\texttt{TangZhu}$.
- Ranks $14$ to $38$: $\texttt{JingYing}$.
- Ranks $39$ to $(n-3)$: $\texttt{BangZhong}$.
However, the “Le Dou” display does not sort by contribution, but by position and level.
After updating positions, output the final list as “Le Dou” would display it, sorted by:
- Position (descending), primary key.
- Level (descending), secondary key.
- Order of appearance in the input (from earlier to later), tertiary key.
Note: absi2011 has no authority to adjust the positions of the guild leader or the vice leaders, including his own.
Input Format
The first line contains a positive integer $n$, the number of members in Xingyue Homeland.
Each of the next $n$ lines contains two strings and two integers: name, position, contribution, and level.
Output Format
Output $n$ lines. Each line contains the name, position, and level in the order “Le Dou” displays after the adjustments.
Explanation/Hint
For $10\%$ of the testdata, $n=3$.
For $40\%$ of the testdata, all contributions are $0$.
For $100\%$ of the testdata, it is guaranteed that:
- $3 \leq n \leq 110$.
- $1 \leq$ name length $\leq 30$.
- All names are pairwise distinct.
- Names contain only visible ASCII characters.
- $0 \leq$ contribution of each person $\leq 10^9$.
- $1 \leq$ level of each person $\leq 150$.
- The position is always one of the following seven:
- $\texttt{BangZhu}$.
- $\texttt{FuBangZhu}$.
- $\texttt{HuFa}$.
- $\texttt{ZhangLao}$.
- $\texttt{TangZhu}$.
- $\texttt{JingYing}$.
- $\texttt{BangZhong}$.
- Initially, the guild has at most:
- $1$ guild leader.
- $2$ vice leaders.
- $2$ guardians.
- $4$ elders.
- $7$ hall masters.
- $25$ elites.
- There is exactly one guild leader.
- There are exactly two vice leaders.
- Exactly one of the vice leaders is named absi2011.
Translated by ChatGPT 5