We are given n records, each is (name, points) for a round. Multiple records can belong to same player. For each player, we consider his best result (maximum points over all his records). Then we need to categorize each player based on comparing his best result to the distribution of best results of all players (including himself). Specifically, we need to determine what percent of players (including himself) have best results <= his best result? Actually the problem statements: The categories are defined by comparing the player's result to thresholds based on percentiles:
-
"noob": if more than 50% of players have better results. That means strictly more than 50% of players have a best result > his best result. Equivalent: his result is worse than at least 50%? Actually "more than 50% of players have better results" means the proportion of players whose best result is greater than his is > 0.5. So his rank (by best result, higher is better) is such that the number of players strictly higher than him > 50% of total players. That's like his percentile (the fraction of players with result <= his) is less than 50%? Let's carefully define: Let M be total number of distinct players m. Let sorted best scores in non-decreasing order (or non-increasing? Better to think in terms of higher is better). If we sort descending: best scores from highest to lowest. Then the player's position (1-indexed) is the number of players with score >= his? Actually we need "more than 50% of players have better results". "Better" means higher score. So count of players with best > his best (strictly greater) > 0.5 * m. So if his score is not unique? If multiple players have same best, then they are not considered better if equal? "Better" means strictly greater. So if his best is X, players with best > X count > 0.5*m -> he is noob.
-
"random": if his result is not worse than the result that 50% of players have, but more than 20% of players have better results. Let's parse: "not worse than the result that 50% of players have" meaning his best >= the value such that 50% of players have that result or worse? Actually typical interpretation: "his result is not worse than the result that 50% of players have" means that at least 50% of players have a result <= his (or his result is at least as good as the result that 50% of players have). In percentile terms, his result is at least the 50th percentile (maybe inclusive). And "more than 20% of players have better results" means strictly more than 20% have results > his. So conditions: proportion of players with score > his > 0.2, and proportion of players with score <= his >= 0.5? Actually "not worse than the result that 50% of players have" could also be interpreted as his result is >= the result that 50% of players have (i.e., median). However the phrasing: "his result is not worse than the result that 50% of players have" likely means that when you look at all players' results, you compute the result that 50% of players have (i.e., the threshold such that 50% of players have results <= that threshold), and his result is not worse than that threshold (i.e., his result >= that threshold). So that condition is his best >= P50 (the 50th percentile value). But because of integer scores and possible ties, we need to be careful.
Alternatively, they could mean: his result is not worse than the result that 50% of players have (meaning at least 50% of players have results <= his). That would be: his rank in sorted descending: if we sort ascending (lower to higher), then the count of players with result <= his is at least 50% of total. That is equivalent to his percentile (fraction of players with result <= his) >= 0.5. But note: "the result that 50% of players have" is ambiguous. However the note in the problem clarifies.
In the first example: players: artem (100), vasya (200), kolya (200), igor (250). So best scores: artem=100, vasya=200, kolya=200, igor=250. m=4.
Now artem: category noob. According to description: "more than 50% of players have better results". 50% of 4 is 2. More than 2 players have better results? Better than 100: scores >100 are vasya (200), kolya(200), igor(250) -> 3 players >100, which is >2, so yes noob.
The random category: vasya and kolya random. For random: condition: "his result is not worse than the result that 50% of players have, but more than 20% of players have better results".
- For vasya (200): Check "not worse than the result that 50% of players have": 50% of 4=2. The result that 50% of players have? If we sort ascending: [100,200,200,250]. The median (50%) might be 200 (since at least 50% <=200? Actually 2/4=50% exactly <=200? Count <=200: artem(100), vasya(200), kolya(200) -> that's 3, which is >50%. But "result that 50% of players have" could be the score such that at least 50% have <= that score. That is indeed 200, because at least 50% have <=200 (3 out of 4). So vasya's result (200) is not worse than 200 (equal), so condition satisfied. Next: more than 20% of players have better results: 20% of 4=0.8, more than 0.8 means at least 1? Actually "more than 20% of players have better results" => number of players with strictly greater score > 0.2*m. For vasya, scores >200: only igor (250) => 1 player. 1 > 0.8? Yes. So both satisfied -> random.
For kolya same as vasya.
For igor: pro. Pro: "if his result is not worse than the result that 99% of players have." Since 99% of 4 is 3.96, so essentially all players? Not worse than the result that 99% of players have means his result >= the score that at least 99% of players have <=? For m=4, the threshold would be the maximum? Usually it means that at least 99% of players have results <= his result (i.e., his result is at the 99th percentile or higher). Since his result is 250, all other players have <=250, so indeed 100% <=250, which >=99%. So pro.
Now check other categories: "average": not worse than result that 80% have, but more than 10% have better results. "hardcore": not worse than result that 90% have, but more than 1% have better results.
So the pattern: For a given player with best score X, let:
- total players = m.
- let count_better = number of players with best score > X.
- let count_worse_or_equal? Actually for the "not worse than the result that p% of players have" we need to interpret. The phrasing "not worse than the result that p% of players have" likely means that his result is at least as good as the score that p% of players have. That is, if we consider the distribution of scores, the threshold T_p is such that at least p% of players have a result <= T_p (i.e., T_p is the p-th percentile, lower bound). Being not worse means his score >= T_p. This is equivalent to saying that the proportion of players with score <= his is at least p%? Actually if his score is X, and if we define T_p as the minimum score such that at least p% of players have score <= T_p, then X >= T_p iff? Not exactly: Suppose we have sorted scores ascending. The p-th percentile value is typically defined as the smallest value such that at least p% of the data is <= that value. Then if X >= that value, does it guarantee that at least p% have <= X? Yes, because if X is >= the p-th percentile, then since the p-th percentile already covers p% of players with scores <= that value, and those players also have scores <= X (since X >= that value), then at least p% have scores <= X. Conversely, if X is such that at least p% have <= X, then the p-th percentile is <= X (since p-th percentile is the minimum score with at least p% <= it). So condition "X >= T_p" is equivalent to "at least p% of players have score <= X". So we can rephrase: The player's best score X satisfies that at least p% of players have a score <= X. And the additional condition for categories except pro and noob: also count_better > q% * m, where q is the "more than q% have better results". Actually categories:
- noob: only condition: count_better > 0.5*m.
- random: count_better > 0.2m AND at least 0.5m have <= X (i.e., proportion <= X >= 0.5).
- average: count_better > 0.1*m AND proportion <= X >= 0.8.
- hardcore: count_better > 0.01*m AND proportion <= X >= 0.9.
- pro: proportion <= X >= 0.99.
Note: In pro there is no condition on count_better; it's simply at least 99% have <= X.
But careful: In pro, the definition says: "if his result is not worse than the result that 99% of players have." That matches proportion <= X >= 0.99.
Now verify with examples: For igor, proportion <=250 = 4/4 =1 >=0.99, so pro. Good.
For artem: proportion <=100 = 1/4 =0.25, which is less than 0.5, so doesn't satisfy random condition. Also count_better = 3 > 2, so noob. That matches.
But note: Could there be a player who meets proportion condition for random but count_better <=0.2m? Then they wouldn't be random; they'd be higher? Let's think: Suppose a player has a score such that at least 50% <= X but count_better <=0.2m. That means less than or equal to 20% have better. Then according to definitions, that would fall into average? Actually average requires proportion <= X >=0.8 and count_better >0.1m. But if count_better <=0.2m but >0.1m? Could be random? No, random requires count_better >0.2m. So if count_better is between 0.1m and 0.2m inclusive? Let's see: If count_better = 0.15m, and proportion <= X = 0.6, then condition for average not satisfied because need >=0.8; random not satisfied because need count_better >0.2; noob? count_better =0.15m not >0.5; what category? Possibly they'd be random? But definitions are exclusive? The problem likely expects each player to fall into exactly one category, and categories are listed in order: noob, random, average, hardcore, pro. They might be mutually exclusive if thresholds are defined appropriately. But we need to see if there could be ambiguous cases. The conditions are:
noob: more than 50% better.
random: (not worse than 50% result) AND more than 20% better.
average: (not worse than 80% result) AND more than 10% better.
hardcore: (not worse than 90% result) AND more than 1% better.
pro: (not worse than 99% result).
Note that "not worse than p% result" is equivalent to proportion <= X >= p/100. And "more than q% better" means proportion > X (strictly) > q/100.
Now consider the intervals: For a given player, let f_le = proportion of players with score <= X, and f_gt = proportion with score > X.
We have f_le + f_gt = 1. Also note that players with same score as X are counted in f_le, not in f_gt. So f_gt = count_better/m.
Now categories:
- noob: f_gt > 0.5.
- random: f_le >= 0.5 and f_gt > 0.2.
- average: f_le >= 0.8 and f_gt > 0.1.
- hardcore: f_le >= 0.9 and f_gt > 0.01.
- pro: f_le >= 0.99.
Now, are these conditions mutually exclusive and covering all possibilities? Possibly they may have overlaps for edge cases? Let's examine boundaries: Suppose f_gt = exactly 0.5? Then noob condition false (since >0.5 required). random condition requires f_gt >0.2 and f_le >=0.5. If f_gt =0.5, then f_le =0.5, so f_le >=0.5 true. But f_gt >0.2 true (0.5>0.2). So random would be satisfied. But does the definition of random say "more than 20% of players have better results"? Yes. And "not worse than the result that 50% of players have". With f_gt =0.5, that means exactly 50% have better? But definition says more than 20% better (strict), but 50% >20%, so ok. However does the "not worse than the result that 50% of players have" hold? f_le =0.5 (i.e., 50% have <= X). That seems to satisfy "not worse than the result that 50% of players have"? Typically if exactly 50% have <= X, then the result that 50% of players have is <= X? Yes, likely. So random would apply. But what about noob? noob requires f_gt >0.5, so if f_gt=0.5, not noob. So random is the correct category. Similarly, if f_gt =0.2 exactly? Then f_gt >0.2 is false, so random not satisfied. But average requires f_gt >0.1 and f_le >=0.8. If f_gt=0.2, f_le=0.8, so average would be satisfied (since f_gt >0.1 and f_le>=0.8). But if f_gt=0.2, that's not >0.2, so random false; average true. However what about "more than 10% better"? Yes (0.2 > 0.1). So average applies. So boundaries: if f_gt exactly 0.2, random false, average true. Similarly, if f_gt = 0.1 exactly? Then average false (since >0.1 needed), but hardcore requires f_gt >0.01 and f_le >=0.9. f_gt=0.1 => f_le=0.9. Then hardcore true if f_gt >0.01? 0.1 >0.01, yes. So hardcore applies. If f_gt = 0.01 exactly? Then hardcore false (needs >0.01), but pro requires f_le >=0.99. f_gt=0.01 => f_le=0.99, so pro applies. If f_gt <0.01, then f_le>0.99, pro also applies (since >=0.99). So categories cover all possibilities with strict inequalities on f_gt where specified, and inclusive on f_le? The phrasing "not worse than the result that p% of players have" suggests inclusive condition (>=). Also the note: "the first player's result is not worse than the result that 50% of players have" when exactly 50%? In the example with two players: first has 100, second has 1000. For first player: "the first player's result is not worse than the result that 50% of players have". Here m=2. f_le for first: <=100: himself only? Actually second has 1000 >100, so f_le = 1/2 = 0.5. So indeed exactly 50% <=100, so they say not worse than the result that 50% of players have. That confirms inclusive (>=). And for second, they say "the second one is not worse than the result that 100% of players have". f_le = 2/2 =1, inclusive. So yes, f_le >= p% is the condition.
Now for f_gt: "more than q% of players have better results" means strictly greater than q% (strict). So f_gt > q/100.
Thus categories are mutually exclusive given these thresholds, because they partition the range of f_gt and f_le. But there could be overlapping if both conditions of two categories hold? Let's test: Could a player satisfy both random and average? For random we need f_le >=0.5 and f_gt >0.2. For average we need f_le >=0.8 and f_gt >0.1. If a player satisfies random, then f_gt >0.2, so automatically >0.1, and f_le >=0.5 but might not be >=0.8. To satisfy both, we need f_le >=0.8 as well, which would then also satisfy average. But does that player also satisfy random? Yes, because random only needs f_le >=0.5 and f_gt >0.2. If f_le >=0.8 and f_gt >0.2, both categories' conditions are true. But problem likely expects only one category per player, and categories are listed in increasing "prestige". Possibly the intended interpretation is that you check categories in order (like a ladder: if pro, then that; else if hardcore; else if average; else if random; else noob). Or perhaps the definitions are meant to be exclusive by design, but we have overlap as shown: a player with f_le >=0.8 and f_gt >0.2 would satisfy both random and average. But does such a situation exist? Let's consider numbers: f_le >=0.8 implies at most 0.2 f_gt. Actually f_le >=0.8 means f_gt <=0.2. But if f_gt >0.2, then f_gt >0.2 and f_gt <=0.2 can't both be true. Because f_le >=0.8 implies f_gt <=0.2. So if f_gt >0.2, then f_gt >0.2, but f_gt <=0.2? No, from f_le >=0.8 we have f_gt = 1 - f_le <= 0.2. So f_gt >0.2 contradicts f_le >=0.8. Therefore a player cannot satisfy both random and average, because random requires f_gt >0.2, and average requires f_le >=0.8 which forces f_gt <=0.2. So they are mutually exclusive. Similarly, random and hardcore? Hardcore requires f_le >=0.9 => f_gt <=0.1, but random requires f_gt >0.2, impossible. So no overlap. Average and hardcore? Average requires f_gt >0.1, hardcore requires f_le >=0.9 => f_gt <=0.1. So they can't both hold because average requires f_gt >0.1, hardcore requires f_gt <=0.1. However if f_gt = exactly 0.1, average false (since >0.1 needed) and hardcore true? Hardcore requires f_gt >0.01 and f_le >=0.9. If f_gt =0.1, f_le=0.9, both hold, so hardcore. That's fine. So categories partition the space:
- noob: f_gt > 0.5.
- random: f_gt > 0.2 and f_gt <= 0.5? Actually also f_le >=0.5. Since if f_gt >0.2 and f_le >=0.5, then automatically f_gt <=0.5? Because if f_le >=0.5, f_gt <=0.5. So random occupies 0.2 < f_gt <= 0.5 and f_le >=0.5. But note if f_gt is exactly 0.5, then f_le=0.5, satisfies. So random includes f_gt in (0.2, 0.5]? Check boundary: f_gt=0.5 -> random true? As argued earlier, yes. But is there conflict with noob? noob requires f_gt >0.5, so 0.5 is not noob. So random includes f_gt=0.5. But then f_gt=0.5 implies f_le=0.5, which is exactly the threshold for "not worse than 50%". So random includes this edge. Similarly, average: f_gt >0.1 and f_le >=0.8. Since f_le >=0.8 implies f_gt <=0.2, so average occupies 0.1 < f_gt <=0.2 and f_le >=0.8. f_gt could be exactly 0.2? Then f_le=0.8. But then is f_gt >0.1? 0.2>0.1, so average true. But also f_gt=0.2 would satisfy random? Random requires f_gt >0.2? Actually random says more than 20% have better results, i.e., f_gt > 0.2. So if f_gt=0.2, it's not >0.2, so random false. So average includes f_gt = 0.2? Check: f_gt = 0.2 exactly. Then f_le =0.8. Does average's condition require f_gt > 0.1? Yes, 0.2 > 0.1. So average would be satisfied. So average includes f_gt = 0.2. But also note f_gt =0.2 leads to f_le=0.8, which is exactly the threshold for "not worse than 80% result"? f_le >=0.8 inclusive, so yes. So average includes f_gt = 0.2.
Similarly, hardcore: f_gt >0.01 and f_le >=0.9. Since f_le >=0.9 => f_gt <=0.1, so hardcore occupies 0.01 < f_gt <= 0.1. Includes f_gt = 0.1? f_gt=0.1 => f_le=0.9, and f_gt >0.01 true, so hardcore true. But note average requires f_gt >0.1, so 0.1 is not >0.1, so average false. So hardcore includes f_gt=0.1.
Pro: f_le >=0.99 => f_gt <=0.01. Pro includes f_gt =0.01? f_gt=0.01 => f_le=0.99, which satisfies f_le >=0.99, so pro true. But hardcore requires f_gt >0.01, so 0.01 is not >0.01, so hardcore false. So pro includes f_gt=0.01. And f_gt <0.01 also pro.
Now what about a scenario where f_le >=0.99 but also f_gt >0.01? That's impossible because f_gt = 1 - f_le <= 0.01. So categories are indeed mutually exclusive and cover all possibilities because for any player f_gt is a number between 0 and 1. The categories define intervals: (0.5,1] -> noob; (0.2,0.5] -> random; (0.1,0.2] -> average; (0.01,0.1] -> hardcore; [0,0.01] -> pro. However, we must also consider the f_le conditions, but they are automatically satisfied in these intervals? Let's verify: If f_gt in (0.2,0.5], then f_le = 1 - f_gt is in [0.5,0.8). Actually (0.2,0.5] gives f_le in [0.5,0.8). For f_gt exactly 0.5, f_le=0.5; for f_gt near 0.2+, f_le near 0.8-. So f_le is at least 0.5? Yes, the minimum f_le is when f_gt max =0.5, then f_le=0.5; if f_gt is larger, say 0.49, f_le=0.51 >0.5. So f_le >=0.5 always. So the "not worse than 50%" condition is automatically satisfied for any f_gt <=0.5? Actually if f_gt = 0.6, f_le=0.4 <0.5, so fails. But for random we require explicitly f_le >=0.5, but it's automatically true if f_gt <=0.5? Because f_le = 1 - f_gt, so f_gt <=0.5 => f_le >=0.5. So indeed the f_le condition is redundant given the f_gt interval? Not exactly: The random definition says both conditions. But if we only used f_gt >0.2, that would also include cases with f_gt in (0.2, 0.5]? Actually if f_gt is >0.2, it could be >0.5 as well, but then f_le<0.5, and that would not satisfy the "not worse than 50%" condition. But if we set the interval to (0.2,0.5] then both conditions hold. So the category can be determined solely by f_gt (the proportion of players with strictly better scores) and maybe also checking f_le thresholds for the lower bound? But we can incorporate both by using f_gt and possibly tie-breaking at exact boundaries? However it's simpler to compute f_gt and f_le and apply conditions in order (pro, hardcore, average, random, noob) because categories are exclusive and covering all.
But careful: The order of checking matters if we use cascading if-else. Since pro condition f_le >=0.99 includes some players who also might satisfy hardcore? Actually as argued, if f_le >=0.99 then f_gt <=0.01. Hardcore requires f_gt >0.01, so f_gt <=0.01 fails hardcore. So if we check pro first, we catch those with f_gt <=0.01. Then check hardcore: f_le >=0.9 and f_gt >0.01. But if f_le >=0.9 and f_gt >0.01, note that if f_le >=0.99, we already captured, so fine. Then average: f_le >=0.8 and f_gt >0.1. But if f_le >=0.8 and f_gt >0.1, could include some with f_le >=0.9? For example, f_le=0.95, f_gt=0.05. This satisfies f_le >=0.9 and f_gt >0.01, so hardcore would capture it. But does it also satisfy average? average requires f_gt >0.1; 0.05 is not >0.1, so not average. So if we check hardcore before average, we correctly categorize. So order: pro, then hardcore, then average, then random, then noob. Or we can compute numeric thresholds.
Simplify: For each player, compute:
- best_i: maximum points for that player.
- m: number of distinct players.
- For each player, compute:
cnt_better = number of players whose best > best_i.
cnt_not_worse = number of players whose best <= best_i (including self). Actually f_le = cnt_not_worse / m.
We can compute these by sorting best scores.
Then determine category based on conditions:
if cnt_not_worse >= ceil(0.99 * m)? Actually condition is proportion >= 0.99, i.e., cnt_not_worse >= 0.99 * m. Since cnt_not_worse is integer, this is equivalent to cnt_not_worse >= ceil(0.99 * m)? But careful: The condition is f_le >= 0.99. For m players, f_le = cnt_not_worse / m. So condition is cnt_not_worse / m >= 0.99 => cnt_not_worse >= 0.99 * m. Since cnt_not_worse integer, we can compute threshold T99 = ceil(0.99 * m)? Let's derive: We need smallest integer cnt such that cnt/m >= 0.99. That is cnt >= 0.99m. If 0.99m is not integer, say m=10, 0.99m=9.9, then cnt >= 9.9 => cnt >= 10? Actually cnt must be integer, so cnt >= 10? But 10/10=1 >=0.99, yes. But 9/10=0.9 <0.99, so need cnt=10. So condition cnt >= ceil(0.99m). Wait ceil(0.99m) for m=10 is ceil(9.9)=10, correct. If m=100, 0.99100=99 exactly, ceil(99)=99. cnt >=99. But 99/100=0.99 exactly, satisfies. So condition cnt_not_worse >= ceil(0.99m). But is that always correct? For m=1, 0.991=0.99, ceil=1, cnt_not_worse=1, so pro. Yes. So we can use ceil.
Alternatively, we can think in terms of rank: Let rank = number of players with score > X (i.e., cnt_better). Then cnt_not_worse = m - rank. The conditions in terms of rank:
- noob: rank > 0.5*m.
- random: rank > 0.2m and m - rank >= 0.5m? Actually m - rank >= 0.5m <=> rank <= 0.5m.
So random: rank > 0.2m and rank <= 0.5m.
- average: rank > 0.1m and m - rank >= 0.8m <=> rank <= 0.2*m.
- hardcore: rank > 0.01m and m - rank >= 0.9m <=> rank <= 0.1*m.
- pro: m - rank >= 0.99m <=> rank <= 0.01m.
Thus categories can be expressed solely in terms of rank (cnt_better) relative to m:
- pro: rank <= floor(0.01m)? Actually rank <= 0.01m. Since rank integer, condition rank <= floor(0.01m)? Let's be careful: We need rank <= 0.01m. For m=100, 0.01m=1, so rank <=1. But if rank=1, then 1 <=1, so pro? But recall pro condition is m - rank >= 0.99m => rank <= 0.01m. For rank=1, 1 <=1, yes pro. But check hardcore condition: hardcore requires rank > 0.01m and rank <= 0.1m. For m=100, rank >1? i.e., rank >=2, and <=10. So rank=1 is pro, rank=2..10 is hardcore. That matches earlier intervals: f_gt <=0.01? Actually f_gt = rank/m. For rank=1, f_gt=0.01 exactly, pro; for rank=2, f_gt=0.02, >0.01, so hardcore. So indeed pro: rank <= floor(0.01m) when 0.01m is integer? For m=99, 0.01m = 0.99. rank <= 0.99 means rank <= 0? Because rank integer, rank <=0. So only rank=0 qualifies. But is that correct? Let's compute using proportion: cnt_not_worse = m - rank. For m=99, need cnt_not_worse >= 0.99m = 98.01 => cnt_not_worse >= 99? Actually 0.9999 = 98.01, so cnt_not_worse >= 98.01 -> integer >=99? Since cnt_not_worse integer, the smallest integer satisfying is 99? 99/99=1 >=0.99, yes. But 98/99 ≈0.9899 <0.99, so not pro. So cnt_not_worse must be 99. That means rank=0. So rank <= 0? Indeed rank <=0. So condition rank <= floor(0.01m) works: floor(0.0199)= floor(0.99)=0, rank <=0. Good.
Now for hardcore: rank > 0.01m and rank <= 0.1m. Since rank integer, we can define: rank_low_hardcore = floor(0.01m) + 1? Actually need rank > 0.01m. So if 0.01m is not integer, say m=99, 0.01m=0.99, then rank > 0.99 means rank >=1. So hardcore lower bound: rank >= ceil(0.01*m + epsilon)? But better to use conditions directly using fractions to avoid rounding issues.
Simpler: For each player, compute:
- rank = number of players with strictly higher best score.
- total = m.
Then compute:
if rank <= 0.01 * total: pro? But careful with floating point. Use integer arithmetic: rank <= total * 1 / 100? However 0.01*total might be fractional. The condition from proportion is: rank / total <= 0.01? Equivalent to rank * 100 <= total? Because rank/total <= 0.01 <=> rank <= total/100. But total/100 may not be integer. rank <= total/100 as a real number. For integer rank, this is equivalent to rank <= floor(total/100) if we are comparing to a real? Let's derive properly:
We need rank <= total * 0.01. That is rank <= total / 100. Since rank is integer, condition rank <= floor(total/100) is not equivalent if total/100 is not integer. For example total=150, total/100=1.5. rank <=1.5 means rank <=1? Actually rank integer: rank can be 1 (since 1 <=1.5) and rank=2 (2 <=1.5 false). So rank allowed: 0,1. So condition rank <= floor(total/100)? floor(1.5)=1, so rank <=1 works. But what about total=101, total/100=1.01, floor=1. rank allowed: 0,1? 1 <=1.01 true. So rank <= floor(total/100) gives 1 <=1, ok. But if total=99, total/100=0.99, floor=0, rank allowed: 0? 0 <=0.99 true, 1 <=0.99 false. So rank <=0 works, matches floor. So condition rank <= floor(total/100) seems to correctly represent rank <= total/100? Because if total/100 is not integer, floor(total/100) is the largest integer less than total/100, and any integer <= total/100 must be <= floor(total/100). Actually is there an integer that is > floor(total/100) but still <= total/100? Since floor(total/100) is the greatest integer <= total/100, any integer greater than floor(total/100) would be at least floor(total/100)+1, and since floor(total/100)+1 > total/100 (because floor(x)+1 > x for any real x), it would violate <= total/100. So yes, rank <= floor(total/100) is equivalent. So pro condition: rank <= floor(total/100).
Similarly, hardcore condition: rank > total * 0.01 and rank <= total * 0.1. That is rank > total/100 and rank <= total/10. For integer rank, rank > total/100 means rank >= floor(total/100)+1. And rank <= total/10 means rank <= floor(total/10) if total/10 is not integer? We need rank <= total/10. Since rank integer, this is rank <= floor(total/10). Because if total/10 = say 9.9, then rank allowed up to 9 (since 9 <=9.9, 10 >9.9). So yes rank <= floor(total/10). So hardcore: floor(total/100)+1 <= rank <= floor(total/10).
But careful: The condition also includes the "not worse than 90% result" i.e., m - rank >= 0.9m, which is equivalent to rank <= 0.1m. So that's captured.
But we must also check that the lower bound for hardcore is rank > 0.01m, but does it also require m - rank >= 0.9m? Yes, that is rank <= 0.1*m. So it's covered.
Now average: rank > total * 0.1 and rank <= total * 0.2. So rank >= floor(total/10)+1? Actually rank > total/10 means rank >= floor(total/10)+1. And rank <= total/5? Wait 0.2 = 1/5, so rank <= total/5. So average: floor(total/10)+1 <= rank <= floor(total/5). But also the condition m - rank >= 0.8m is automatically satisfied if rank <= 0.2m? Yes.
Random: rank > total * 0.2 and rank <= total * 0.5. So rank >= floor(total/5)+1? Actually rank > 0.2m => rank >= floor(0.2m)+1? But careful: if 0.2m is integer, e.g., m=5, 0.25=1 exactly. rank >1 means rank>=2. So lower bound: rank >= floor(0.2m) + 1? But floor(0.2m) is 1, so +1 =>2, correct. For non-integer, say m=7, 0.27=1.4, floor=1, rank >1.4 means rank>=2, so floor+1=2 works. So lower bound = floor(0.2m) + 1 if 0.2m not integer? Actually we need rank > 0.2m. Since rank is integer, condition is rank >= floor(0.2m) + 1 if 0.2m is not integer? Let's define: Let t = 0.2*m. Then rank > t. Equivalent to rank >= floor(t) + 1 because floor(t) is the greatest integer less than or equal to t. If t is integer, then floor(t) = t, and we need rank > t => rank >= t+1. So in that case, floor(t)+1 = t+1. So the condition can be uniformly expressed as rank >= floor(t) + 1? For integer t, floor(t) = t, then floor(t)+1 = t+1, which is > t, good. For non-integer, floor(t) < t, so floor(t)+1 may be > t? Not necessarily: if t=1.4, floor=1, floor+1=2, and 2 > 1.4, yes. What if t=0.9, floor=0, floor+1=1, 1 > 0.9, yes. So rank >= floor(t)+1 is equivalent to rank > t. Because floor(t)+1 is the smallest integer strictly greater than t. So yes.
Thus we can compute integer thresholds:
Let m = number of distinct players.
Define:
pro_max_rank = floor(m * 1 / 100) // 0.01m floor
hardcore_max_rank = floor(m * 10 / 100) // 0.1m floor
average_max_rank = floor(m * 20 / 100) // 0.2m floor
random_max_rank = floor(m * 50 / 100) // 0.5m floor
But careful: For random_max_rank, note that random includes rank <= 0.5m. If 0.5m is integer, rank can equal that. So random_max_rank = floor(0.5m). For average_max_rank = floor(0.2m), etc.
Now lower bounds:
hardcore_min_rank = pro_max_rank + 1 // because rank > 0.01m => rank >= floor(0.01m)+1
average_min_rank = hardcore_max_rank + 1 // rank > 0.1m
random_min_rank = average_max_rank + 1 // rank > 0.2m
noob_min_rank = random_max_rank + 1 // rank > 0.5*m
But also need to ensure the conditions on the "not worse" side are automatically satisfied? For random: need also rank <= 0.5m, which we have. For average: need rank <= 0.2m, captured by average_max_rank. For hardcore: rank <= 0.1m, captured by hardcore_max_rank. For pro: rank <= 0.01m, captured by pro_max_rank. And noob: rank > 0.5m, which is noob_min_rank <= rank. So these conditions are sufficient and no need to separately check the "not worse" side because they are the complement of the "better" side? Actually we must also consider that for random we require "not worse than the result that 50% of players have", which is equivalent to rank <= 0.5m. But we already have that as upper bound. For average, need rank <= 0.2*m, which we have. So yes, the rank intervals fully define the categories:
Let r = number of players with strictly greater best score.
Then:
- if r <= floor(m/100) → pro
- else if r <= floor(m/10) → hardcore (since r > floor(m/100) automatically due to previous else)
- else if r <= floor(m/5) → average
- else if r <= floor(m/2) → random
- else → noob
But careful: The else if chain ensures that each interval is exclusive and we are checking in increasing r. For example, if r <= floor(m/100), pro; else (r > floor(m/100)), then check if r <= floor(m/10). But does this correctly handle the strictness? For hardcore, the condition requires r > 0.01m and r <= 0.1m. Since we are in the else branch (r > floor(m/100)), we know r >= floor(m/100)+1. But is it possible that r > floor(m/100) but still r <= floor(m/10) and yet r might be <= 0.01m? No, because r > floor(m/100) implies r >= floor(m/100)+1. But could it be that 0.01m is not integer and r = floor(m/100)+1 is still <= 0.01m? For instance, m=150, floor(m/100)=1, 0.01m=1.5. r=2 > 1.5? Actually 2 > 1.5, yes. So r > 0.01m. So correct. But if m=101, floor(m/100)=1, 0.01m=1.01. r=2 >1.01, yes. r=1? That would be <= floor(m/100) and would be pro. So the else branch excludes r=1 if floor(m/100)=1? But for m=101, floor(101/100)=1, so r=1 is pro. So hardcore starts at r=2. That matches condition rank > 0.01m, because for m=101, 0.01m=1.01, so rank=1 is not >1.01, so not hardcore, but is pro? Pro condition rank <= 0.01*m? 1 <= 1.01 true, so pro. So correct.
Now what about average: else if r <= floor(m/5). But we need to ensure that r > 0.1m. Since we are in else branch after checking r <= floor(m/10) (which catches r <= floor(m/10)), the else if for average only executes if r > floor(m/10). So that ensures r > 0.1m? Actually if r > floor(m/10), that does not guarantee r > 0.1m, because if 0.1m is not integer, say m=15, 0.1m=1.5, floor(m/10)=1. Then r > 1 means r >=2. But is r=2 > 1.5? Yes. So condition holds. For m=10, 0.1m=1, floor(10/10)=1. r > 1 means r >=2. That's >1, good. So else if r <= floor(m/5) combined with the fact that we are in else branch after r <= floor(m/10) ensures both conditions.
Similarly, random: else if r <= floor(m/2) after not satisfying r <= floor(m/5) ensures r > floor(m/5) and r <= floor(m/2). That corresponds to r > 0.2m and r <= 0.5m. But need to ensure r > 0.2m. Since we only know r > floor(m/5) because we didn't satisfy the previous condition. floor(m/5) is the greatest integer <= 0.2m. So r > floor(m/5) implies r >= floor(m/5)+1, which is > 0.2m? Not necessarily if 0.2m is integer. Example: m=5, 0.2m=1, floor(5/5)=1. r > 1 => r >=2. That's >1, good. If m=10, 0.2m=2, floor(10/5)=2. r > 2 => r >=3, which >2, good. So yes.
Thus simple integer rank comparisons work.
Now we must also consider that the "better" condition is strict: only strictly higher scores count as better. So ranking: For each player, r = count of players with best > best_i. That is essentially the number of players with strictly higher score.
Implementation steps:
- Read n.
- For each record, read name and score. Maintain a dict (map) name -> best score (max). Update if higher.
- After processing all, we have m distinct players, each with best score.
- Extract list of best scores (maybe store in list along with names). We'll need to compute for each player r = number of players with strictly higher best.
We can sort the list of best scores descending. Or we can count frequencies.
Given m <= 1000, we can for each player iterate over all others to count better. O(m^2) = 1e6, fine. But we can also sort and use prefix sums.
Simplify: Create list of best scores. Sort descending. Then for each unique score? But multiple players can have same best score. For a player with score s, the number of players with strictly higher score is the number of players with score > s. So we can compute a frequency map of scores, then for each player compute r as sum of frequencies for scores > s.
Given small m, O(m^2) is fine.
But we need to output each player's category. The output order arbitrary.
Edge Cases:
-
m = 1. Then for the only player, r = 0. Check conditions: r <= floor(1/100)=0, so pro. Indeed the player's result is not worse than the result that 99% of players have? Since there's only one, 99% of players is essentially 1? Actually 99% of 1 is 0.99, so his result is not worse than that? Since he is the only player, he has the best, so he belongs to pro. This matches expectation: He is not worse than 100% of players, which is >=99%.
-
m = 2. Scores maybe equal or different. For two players both with same best: r=0 for both (since none strictly higher). So both pro? Check conditions: r=0 <= floor(2/100)=0? floor(0.02)=0, yes. So pro. That matches second example: both have 200 and 1000? Actually second example: vasya has best=1000? Wait input:
3
vasya 200
kolya 1000
vasya 1000
So best for vasya = max(200,1000)=1000, kolya=1000. Both 1000. So r=0 for both, pro. Output matches.
If one has 100, other 1000: then for player with 100: r = 1 (other has 1000 > 100). floor(2/100)=0, r=1 >0, so not pro. Check hardcore: r <= floor(2/10)= floor(0.2)=0? r=1 >0, not hardcore. average: r <= floor(2/5)= floor(0.4)=0, not. random: r <= floor(2/2)=1, r=1 <=1, and because we are in else if chain: after checking earlier conditions false, we check random? But we must ensure that random condition includes r <= floor(m/2) and also r > floor(m/5) (implicit from failing previous). Let's trace: m=2, r=1.
- pro: r <= floor(2/100)=0? false.
- else if r <= floor(2/10)=0? false.
- else if r <= floor(2/5)=0? false.
- else if r <= floor(2/2)=1? true, so random. So category random. But is that correct according to problem? Let's check the note: they said for two players where first 100, second 1000, the first player's result is not worse than the result that 50% of players have, and the second is not worse than 100%. They didn't specify categories, but based on definitions: first player: more than 50% have better results? There are 2 players, 50% of 2 =1. More than 1? That would be >1, i.e., at least 2? But only one player has better (the second), so not more than 50% (since 1 is not >1). So not noob. Then random condition: his result is not worse than the result that 50% of players have (true) and more than 20% have better results (20% of 2 = 0.4, more than 0.4 means at least 1 better? Since 1 > 0.4, yes). So random is appropriate. The second player: more than 1% better? 1% of 2 = 0.02, better players: 0? 0 is not >0.02, so not hardcore? But pro: result not worse than 99%: 99% of 2 = 1.98, so not worse than result that 99% have means he should be pro? Let's compute: f_le for second = 2/2=1 >=0.99, so pro. According to our rank method: r=0 <= floor(2/100)=0, so pro. Good.
Thus algorithm seems consistent.
One more nuance: The problem statement says: "When the percentage is calculated the player himself is taken into account." We already accounted.
Thus solution: compute best for each player, compute total distinct m, for each compute r (strictly higher count). Then assign category based on r thresholds using integer divisions.
But need to be careful with rounding: floor(m/100) is integer division in C++ (m/100). But for negative? no. In Python, // works. But we must ensure that the thresholds correctly reflect the conditions as derived.
Let's double-check thresholds with various m to ensure they match the proportional conditions.
General: For a category defined by:
- lower bound L (exclusive) of f_gt > q, i.e., r/m > q => r > q*m.
- upper bound U (inclusive) of f_gt <= Q? Actually categories have r <= Qm (since f_gt <= some value). For random: r <= 0.5m. So we need integer r satisfying r > 0.2m and r <= 0.5m.
Our derived integer intervals using floor:
r <= floor(0.5*m) as upper bound for random.
But is r <= floor(0.5m) equivalent to r <= 0.5m? For integer r, yes: r <= floor(0.5m) means r is at most the largest integer <= 0.5m. If 0.5m is integer, floor(0.5m)=0.5m, so r <= exactly that. If 0.5m is not integer, then floor(0.5m) < 0.5m. But any integer r satisfying r <= 0.5m will also satisfy r <= floor(0.5m) because if r <= 0.5m, and if 0.5m is not integer, the maximum integer allowed is floor(0.5m). So r <= floor(0.5m) is equivalent. Good.
Now lower bound: r > 0.2m. For integer r, that is r >= floor(0.2m) + 1. Since our cascade ensures we only reach random if previous checks failed, and previous checks were for r <= floor(0.2m) (average) and lower. So by the time we check random, we know r > floor(0.2m). That is exactly r >= floor(0.2m)+1. That matches r > 0.2m? Let's verify equivalence: If r >= floor(0.2m)+1, does it guarantee r > 0.2m? Yes, because floor(0.2m)+1 > 0.2m (since floor(x)+1 > x for any real x). Conversely, if r > 0.2m, then r >= floor(0.2m)+1 (since r integer and > x implies r >= floor(x)+1). So equivalent. So using cascade with thresholds floor(0.2m) and floor(0.5m) works.
Now let's test some specific m values:
m=3.
Compute thresholds:
floor(3/100)=0
floor(3/10)=0
floor(3/5)= floor(0.6)=0? Actually 3/5=0.6, floor=0.
floor(3/2)=1
Categories:
- r <=0 => pro
- else if r <=0 => hardcore (but since we use else if after pro, r>0, r<=0 false, so not hardcore)
- else if r <=0 => average (false)
- else if r <=1 => random (r=1 qualifies)
- else noob (r>=2)
Now check all possible r values:
r=0 (best score is highest, maybe tie? if all same, r=0): pro.
r=1: random.
r=2: noob.
Is this correct according to proportions? For m=3:
- Pro: f_le >=0.99 => need r <= 0.03 => r=0 only. So pro only r=0.
- Hardcore: r >0.03 and r <=0.3 => r in [1? 0.03< r <=0.3 => r=1? 1/3=0.333, which >0.3, so r=1 not <=0.3. Actually 0.3m=0.9, so r <=0.9 => r <=0? floor? So hardcore: r >0.03 and r <=0.3m=0.9 => r <=0 (since integer). So no r. So hardcore none. That matches our thresholds: floor(3/10)=0, so hardcore would require r <=0 but r>0, impossible.
- Average: r >0.3 and r <=0.6 => 0.3m=0.9, 0.6m=1.8 => r >0.9 and <=1.8 => r=1? 1 >0.9 and 1 <=1.8 yes. So average would include r=1. But our cascade gave random for r=1. Wait conflict! Let's compute properly:
According to definition:
- average: "not worse than the result that 80% of players have, but more than 10% of players have better results."
Interpretation: f_le >=0.8 and f_gt >0.1.
m=3:
f_le >=0.8 => m - r >= 0.8m => 3 - r >= 2.4 => r <= 0.6 => r <= 0.6? Actually 3 - r >= 2.4 => r <= 0.6. Since r integer, r <= 0? Because 0.6 means r <=0? Wait solve: 3 - r >= 2.4 => -r >= -0.6 => r <= 0.6. Since r integer, r can be 0. r=0 satisfies r <=0.6. r=1 gives 3-1=2 which is not >=2.4 (2 <2.4). So f_le >=0.8 only for r=0. So average would require r=0 and also f_gt >0.1 => r/m >0.1 => r >0.3? Actually >0.1m? More than 10% better: f_gt >0.1 => r/m >0.1 => r > 0.1*m = 0.3 => r >0.3. For r=0, r >0.3 false. So no player qualifies for average. So average is empty.
Random: f_le >=0.5 => 3 - r >= 1.5 => r <= 1.5 => r <=1 (since integer). So r=0 or 1 satisfy f_le >=0.5. And f_gt >0.2 => r/m >0.2 => r >0.6 => r >=1? Since r integer, r >0.6 => r >=1. So random requires r >=1 and r <=1, so only r=1 qualifies. So random includes r=1.
Noob: f_gt >0.5 => r/m >0.5 => r >1.5 => r >=2. So r=2 qualifies.
Thus for m=3, categories: r=0 -> ? It satisfies f_le >=0.5? Actually r=0 gives f_le=1 >=0.5, and f_gt=0 >0.2? No, f_gt >0.2 false. So not random. It also satisfies f_le >=0.8 but f_gt >0.1 false. It also satisfies f_le >=0.9? f_gt >0.01? For hardcore: f_le >=0.9 => 3-r >=2.7 => r <=0.3 => r=0 qualifies; f_gt >0.01 => r >0.03 => r>=1? Actually >0.03*m? More than 1% better: r/m >0.01 => r >0.03 => r >=1? Since r integer, r >0.03 means r>=1. So r=0 fails f_gt >0.01. So not hardcore. Pro: f_le >=0.99 => 3-r >=2.97 => r <=0.03 => r=0 qualifies? 0 <=0.03 yes. So r=0 is pro. That matches our cascade: r=0 -> pro. Good.
So the thresholds we derived (pro: r <= floor(m/100)) gave floor(3/100)=0, so r=0 pro. Good.
Average: our cascade gave else if r <= floor(m/5) (floor(0.6)=0) but we would only get there if r > floor(m/10). For m=3, floor(m/10)=0, so if r>0, r>=1, then check r <= floor(m/5)=0, false, so not average. That matches.
Random: else if r <= floor(m/2) (floor(1.5)=1) and r > floor(m/5) implicitly because previous check failed. For r=1, it's true, so random. Good.
So our cascade seems correct.
Now test m=10.
Compute thresholds:
floor(10/100)=0
floor(10/10)=1
floor(10/5)=2
floor(10/2)=5
Cascade:
r <=0 -> pro
r <=1 -> hardcore (since else if after pro, but r must be >0 to reach else if, but if r=1, r <=1 true, so hardcore)
r <=2 -> average (if r=2, r>1? Actually else if after hardcore; for r=2, r <=2 true, so average)
r <=5 -> random (if r=3,4,5)
r >5 -> noob
Now check proportional conditions:
- Pro: r <= floor(10/100)=0, i.e., r=0. f_le=1 >=0.99? 1 >=0.99 yes.
- Hardcore: r > 0.0110=0.1 and r <= 0.110=1 => r <=1 and >0.1 => r=1 qualifies. f_le=0.9 >=0.9, f_gt=0.1 >0.01? Actually f_gt =0.1 >0.01, yes. So hardcore = r=1.
- Average: r >0.110=1 and r <=0.210=2 => r=2 qualifies. f_le=0.8, f_gt=0.2 >0.1? 0.2>0.1 yes. So average = r=2.
- Random: r >0.210=2 and r <=0.510=5 => r=3,4,5 qualifies. For r=5, f_gt=0.5, f_le=0.5, but condition for random: f_le >=0.5 and f_gt >0.2. f_gt=0.5 >0.2, yes. So r=5 qualifies as random.
- Noob: r >0.5*10=5 => r=6,7,8,9? Actually max r =9? Since m=10, r can be up to 9. So noob = r=6..9.
Our cascade gave random for r=5, and noob for r=6+. That matches.
Now test m=11.
Compute thresholds:
floor(11/100)=0
floor(11/10)=1 (since 1.1 floor 1)
floor(11/5)=2 (since 2.2 floor 2)
floor(11/2)=5 (since 5.5 floor 5)
Cascade:
r=0 -> pro
r=1 -> hardcore? r <=1 true -> hardcore
r=2 -> average? r <=2 true -> average
r=3,4,5 -> random? r <=5 true -> random
r>=6 -> noob
Now check proportional:
- Pro: need r <= 0.01*11 = 0.11 => r=0.
- Hardcore: r > 0.11 and r <= 1.1 => r <=1? Actually r <= 1.1 => r can be 1. And >0.11 => r>=1? But r=1 >0.11 yes, and <=1.1 yes. So hardcore = r=1.
- Average: r > 1.1 and r <= 2.2 => r >1.1 => r>=2, and r <=2.2 => r=2 qualifies. So average = r=2.
- Random: r >2.2 and r <=5.5 => r>=3 and r<=5 => r=3,4,5.
- Noob: r >5.5 => r>=6.
Matches cascade.
Now test m=200 (larger). Should be fine.
Thus algorithm is sound.
Now we need to output m (distinct players) and then each player's name and category.
Implementation details:
- Read n.
- Use dictionary (Python dict) to store for each name the maximum points.
- After reading all, we have a list of (name, best). m = len(dict).
- Extract list of best scores. We'll compute r for each player. To compute r, we could sort the list of best scores, but need to map back to players. Simpler: Since m <= 1000, for each player, loop through all players to count how many have strictly higher best. O(m^2) = up to 1e6, fine.
But we can also compute frequency of each score, then for each player compute sum of frequencies for scores > his best. That would be O(m + distinct_scores) but also fine.
We'll just do double loop.
Pseudo:
players = list of (name, best)
m = len(players)
for i in range(m):
cnt_better = 0
for j in range(m):
if players[j][1] > players[i][1]:
cnt_better += 1
r = cnt_better
Then assign category based on r and m.
Define thresholds:
t_pro = m // 100
t_hardcore = m // 10
t_average = m // 5 # because 20% = 1/5
t_random = m // 2 # 50% = 1/2
Then:
if r <= t_pro:
cat = "pro"
elif r <= t_hardcore:
cat = "hardcore"
elif r <= t_average:
cat = "average"
elif r <= t_random:
cat = "random"
else:
cat = "noob"
But careful: The order: pro has lowest r, then hardcore, then average, then random, then noob. However, we must ensure that the conditions are exclusive and the thresholds align. For m=10, t_pro=0, t_hardcore=1, t_average=2, t_random=5. This works as above.
Check m=3: t_pro=0, t_hardcore=0, t_average=0, t_random=1. Then:
r=0 -> r <= t_pro (0) true -> pro.
r=1 -> r <= t_pro? false. r <= t_hardcore? 1 <=0 false. r <= t_average? false. r <= t_random? 1<=1 true -> random. That's correct (hardcore and average not possible because thresholds 0, but r=1 doesn't fall into them). So fine.
But we need to ensure that for cases where t_hardcore equals t_pro (e.g., m < 10, t_hardcore=0, t_pro=0), the elif r <= t_hardcore would be true for r=0, but r=0 already caught by pro. Since we check pro first, it's fine. For r>0, r <= t_hardcore false, so goes to average, etc.
Thus this if-elif chain works.
Now confirm with m=1: t_pro=0, t_hardcore=0, t_average=0, t_random=0. r=0 -> pro.
m=2: t_pro=0, t_hardcore=0, t_average=0, t_random=1. Then:
- r=0 -> pro.
- r=1 -> pro? r <= t_pro? false; r <= t_hardcore? false; r <= t_average? false; r <= t_random? true -> random. That matches expectation: player with lower score gets random if only one other has higher? Actually earlier we computed for two players with different scores: the lower gets random, the higher gets pro. So yes.
Now test m=100: t_pro=1, t_hardcore=10, t_average=20, t_random=50. Then:
- r=0,1 -> pro (since <=1). But careful: r=1 corresponds to f_gt=0.01. According to condition, pro: f_le >=0.99 => r <=0.01*m =1, inclusive. So r=1 is pro. But does our earlier definition say pro if result not worse than result that 99% of players have. For m=100, 99% means 99 players have <= his result. That would require r <=1. So r=1 qualifies as pro. Good.
- r=2..10 -> hardcore? Actually r <=10 includes r=2..10. But condition for hardcore: r > 1 and r <=10. So yes.
- r=11..20 -> average.
- r=21..50 -> random.
- r=51..99 -> noob.
Now check r=10: f_gt=0.1, f_le=0.9. That's exactly the boundary for hardcore. According to condition, hardcore requires f_gt >0.01 (true) and f_le >=0.9 (true). So r=10 is hardcore. That matches. r=20: f_gt=0.2, f_le=0.8. That's average boundary. So r=20 is average. r=50: f_gt=0.5, f_le=0.5. That's random boundary. So r=50 is random. Good.
Now what about r=0? Pro.
Thus categorization is consistent.
Implementation details: In Python, dictionary to store max, then convert to list.
Edge Cases: Names are unique, so dictionary key is name.
Input constraints: n up to 1000, points up to 1000. So fine.
Output: Print m, then each line with name and category, any order.
Testing on given examples:
Example1:
Input:
5
vasya 100
vasya 200
artem 100
kolya 200
igor 250
Process:
Records:
vasya: max(100,200)=200
artem:100
kolya:200
igor:250
m=4
Compute r:
artem (100): others have 200,200,250 >100 => r=3
vasya (200): others: artem 100 (not >), kolya 200 (not >, equal), igor 250 (>200) => r=1? Actually check strictly greater: igor 250 >200, others not >. So r=1
kolya similarly r=1
igor (250): none >250 => r=0
Now thresholds: m=4, t_pro = 4//100 = 0; t_hardcore = 4//10 = 0; t_average = 4//5 = 0; t_random = 4//2 = 2.
Categorize:
artem r=3 -> r<=t_pro? no; <=t_hardcore? no; <=t_average? no; <=t_random? 3<=2? false -> else noob. So artem noob. (But expected noob? Actually example output: artem noob. Yes.)
vasya r=1 -> check: <=t_pro? 0? no; <=t_hardcore? 0? no; <=t_average? 0? no; <=t_random? 1<=2 true -> random. So vasya random.
kolya r=1 -> random.
igor r=0 -> <=t_pro true -> pro. So igor pro.
Matches.
Example2:
Input:
3
vasya 200
kolya 1000
vasya 1000
Processing:
vasya: max(200,1000)=1000
kolya:1000
m=2, thresholds: t_pro=0; t_hardcore=0; t_average=0; t_random=1.
r for vasya: other kolya has 1000, not > (equal) so r=0 -> pro.
r for kolya: other vasya 1000 not > so r=0 -> pro.
Output both pro. Matches.
Thus solution works.
Now discuss possible pitfalls: Are there any players with same best scores? Yes. Then r (strictly greater) counts only those with higher. So players with same best will have same r? Not necessarily if there are higher scores, but among themselves, they are not better. That's correct.
One more nuance: The definition says: "if his result is not worse than the result that p% of players have". We interpreted as f_le >= p%. In the case where there are ties, does that hold? Yes.
Now, we should confirm with the note: For two players: first 100, second 1000. They say first player's result is not worse than the result that 50% of players have. That is because 50% of players (1 out of 2) have result <=100? Actually one player (himself) has 100, the other has 1000 >100, so only 1 out of 2 have <=100 = 50%. So yes.
Now, we must output m (distinct players) on first line. Then each player's name and category.
Thus algorithm is straightforward.
Now consider performance and implement.
But wait, the problem statement: "Vasya has been playing Plane of Tanks with his friends the whole year. Now it is time to divide the participants into several categories depending on their results." It might be that the same player appears multiple times (as records). But we already considered best result.
Now the output order arbitrary.
Now I'll code in Python.
Implementation steps in code:
def solve():
import sys
input_data = sys.stdin.read().strip().split()
if not input_data: return
it = iter(input_data)
n = int(next(it))
best = {}
for _ in range(n):
name = next(it)
points = int(next(it))
if name in best:
if points > best[name]:
best[name] = points
else:
best[name] = points
m = len(best)
# Convert to list
players = list(best.items()) # list of (name, best)
# Precompute r for each
# Might be O(m^2)
categories = []
t_pro = m // 100
t_hardcore = m // 10
t_average = m // 5
t_random = m // 2
for name, score in players:
cnt_better = 0
for _, s2 in players:
if s2 > score:
cnt_better += 1
r = cnt_better
if r <= t_pro:
cat = "pro"
elif r <= t_hardcore:
cat = "hardcore"
elif r <= t_average:
cat = "average"
elif r <= t_random:
cat = "random"
else:
cat = "noob"
categories.append((name, cat))
# Output
print(m)
for name, cat in categories:
print(name, cat)
Test with examples.
Now double-check threshold definitions: t_average = m // 5 because 20% = 1/5. t_hardcore = m // 10 because 10% = 1/10. t_pro = m // 100 because 1% = 1/100. t_random = m // 2 because 50% = 1/2.
But is there any category with p% being 80% and 90%? Those are the "not worse than" thresholds. But we used rank conditions, which implicitly use those. For average, we require r <= 0.2*m (i.e., rank <= floor(m/5)). That ensures f_le >= 0.8. So that's correct.
Now check edge case m = 0? Not possible, n>=1 so at least one record, so m>=1.
Now consider scenario where there are many players with same high score. Suppose m=100, all have same best score 500. Then for each player, cnt_better = 0. So r=0 <= t_pro=1, so all pro. That seems plausible: if everyone has same result, then each player's result is not worse than 99% of players (since 100% <= their result). So pro.
Now if there is distribution, correct.
Now potential pitfalls: The problem says "The name of each player should be printed only once. Player names with respective categories can be printed in an arbitrary order." So we are good.
Now let's test some additional cases manually:
Case: n=1, single record: a 500. m=1, thresholds all zero. r=0 -> pro. Output: 1, a pro. Acceptable.
Case: n=4 with scores: a 10, b 20, c 30, d 40. m=4.
Compute r:
a (10): >10 are b,c,d => r=3 -> noob (since r=3 > t_random=2? t_random=2, r=3 not <=2, so noob)
b (20): >20 are c,d => r=2 -> random? Check: t_random=2, r=2 <=2 => random.
c (30): >30 is d => r=1 -> random? r=1 <=2 => random.
d (40): r=0 -> pro? t_pro=0 => pro.
But let's verify with definitions: m=4.
- d: best=40, f_le=1 >=0.99, pro.
- c: best=30, f_gt=1/4=0.25, >0.2? 0.25>0.2 yes; f_le=3/4=0.75 >=0.5? Actually random requires f_le >=0.5 (true) and f_gt >0.2 (true). So random. But also average? average requires f_le >=0.8 and f_gt >0.1, but f_le=0.75 <0.8 so not average. So random.
- b: best=20, f_gt=2/4=0.5, f_le=0.5. Random requires f_gt >0.2 (0.5>0.2) and f_le >=0.5 (0.5>=0.5). So random. But does it satisfy "not worse than result that 50% have"? Yes, because 50% have <=20? Actually two players have <=20 (a and b) => 50%. So random.
- a: best=10, f_gt=3/4=0.75 >0.5 -> noob. So matches.
Thus correct.
Now consider scenario where there are many players with same score causing r to be same across many. Our method works.
Now I think solution is correct.
But we need to be cautious about integer division: In Python, // does floor division. For positive m, fine.
Now we can also compute thresholds using floor division as described.
One more nuance: The thresholds for pro, hardcore, etc., are defined based on percentages; we used floor for upper bounds. But what about the condition "more than 1% of players have better results" for hardcore? That is r > 0.01m. Our cascade ensures r > t_pro because we used else if after r <= t_pro. Since t_pro = floor(0.01m), the condition r > t_pro is equivalent to r > 0.01m? Let's check: if 0.01m is not integer, say m=150, 0.01m=1.5, t_pro=1. r >1 means r>=2. And 2 > 1.5, true. So hardcore includes r=2,3,... up to t_hardcore=15. Good. If 0.01m is integer, say m=100, 0.01m=1, t_pro=1. r >1 means r>=2. And 2 >1, true. So hardcore includes r=2..10. But note: r=1 was pro, because r <=1, so it's pro. That matches the condition that pro includes r <=0.01m (which includes r=1 when 0.01m=1). And hardcore requires r >0.01m, so r=1 is not hardcore. Good.
Similarly for average: after hardcore, we check r <= t_hardcore, but if r > t_hardcore, then it goes to average? Actually our chain is: if r <= t_pro -> pro; elif r <= t_hardcore -> hardcore; elif r <= t_average -> average; ... So for average, it requires r > t_hardcore (since not <= t_hardcore) and r <= t_average. That ensures r > 0.1m? Check: t_hardcore = floor(0.1m). If 0.1m is not integer, say m=15, 0.1m=1.5, t_hardcore=1. r >1 means r>=2. And 2 >1.5, so correct. If 0.1m is integer, say m=10, 0.1m=1, t_hardcore=1. Then r >1 => r>=2, and 2 >1, correct. So average condition satisfied.
Thus cascade is correct.
Now we should confirm that for m values where thresholds might cause some categories to be missing, it's fine.
Now coding.
Potential improvements: Use sorting to compute r more efficiently: sort players by best score descending. Then iterate, keeping count of players with higher scores. Since scores may repeat, careful: For each player, r = number of players with strictly higher score. If we sort descending, then for each player, we can assign r as the number of players before him that have strictly higher score. However, with ties, need to treat. But O(m^2) is fine.
Edge Cases: Names are lowercase Latin letters, length 1-10.
Now produce final solution.
But wait: The problem statement might have an alternative interpretation: "The player belongs to category: * 'noob' — if more than 50% of players have better results; * 'random' — if his result is not worse than the result that 50% of players have, but more than 20% of players have better results; ..." It could be read as: The thresholds are based on "result that p% of players have", which might be the p-th percentile value. And "his result is not worse than that result" means his result >= that percentile value. That's what we used.
But one nuance: The phrase "the result that 50% of players have" might be interpreted as the median result (the value such that 50% of players have that result or less). That's consistent.
Now confirm using note: In the first example they said: "vasya and kolya have best results not worse than the results that 75% players have (both of them and artem)" Wait 75%? That seems different: They said "75% players have" but there are 4 players, both of them and artem => 3 players out of 4 = 75%. But according to our calculation, vasya and kolya have f_le = number of players <= 200 = 3 (artem, vasya, kolya) = 75%. So they say not worse than result that 75% of players have. But the definition of random says "not worse than the result that 50% of players have". So why are they referring to 75%? Actually they are explaining that they belong to random because they satisfy condition? Possibly they are just illustrating the percentiles. The random category uses 50% as threshold, but they mention that they are not worse than 75%, which is true but not needed. So it's consistent.
All good.
Now just implement.
However, need to read input carefully. n up to 1000, lines with name and points. Use sys.stdin.
Now write final answer.
Wait: There's also a note about "the best result obtained by the player and the best results of other players." That we used.
Thus final solution.
I'll produce explanation and code.
But before final, ensure that the output order is arbitrary, but we might need to output the player names only once. We'll output as we iterate through the dictionary items.
Testing code on examples.
Now include in final answer.
Let's also test some edge case: n=1000, all distinct names, scores random. Computation O(m^2) = 1e6, fine.
Now potential nuance: The percentages are taken including the player himself. Already accounted.
Now final answer.
But consider this scenario: Suppose m=100, and r=1 is pro. That means a player with second highest score (if one player has higher) is still pro? Let's test: Highest has r=0 -> pro. Second highest has r=1 -> also pro? According to our thresholds, yes. But is that correct according to definition? For m=100, pro requires "not worse than the result that 99% of players have". 99% of 100 is 99 players. That means the player's result must be >= the result that at least 99 players have <= his. If the player is second highest, then number of players with <= his result includes himself and all below, which could be 99? Let's see: If there are 100 players sorted descending: highest (score 1000), second (score 999), others lower. Number of players with <= second's score: all except the highest? That is 99 players (second plus 98 others). So indeed 99% of players have result <= his. So second highest qualifies as pro. That seems plausible.
What about third highest? If scores are all distinct, third highest would have 98 players with <= his (including himself). 98/100=0.98 <0.99, so not pro. So only the top 2? Actually top 2? For 100, 99% means at least 99. So top 1? Highest has 100 <= his? Actually highest has all 100 <= his (since he is max). That's 100, >=99. So highest qualifies. Second highest: number of players <= his = 99 (all except highest). 99 >=99, qualifies. So both highest and second highest are pro. That matches r=0 or 1. So pro includes up to floor(0.01m) = 1? Actually floor(0.01100)=1, so r <=1 includes r=0,1. So top two. That seems correct.
But does the definition "not worse than the result that 99% of players have" exactly mean that at least 99% have <= his result? Yes. So if 99% of 100 is 99, then second highest qualifies. So correct.
Now consider hardcore: top 10%? Actually hardcore requires f_le >=0.9, i.e., at least 90% <= his result. For m=100, that means at least 90 players <= his result. That would be the top 10 players? Actually if scores distinct, the 10th highest (from top) would have how many <=? If 10th highest, there are 90 players with lower or equal? Let's see: sorted descending: positions 1..100. For player at position p (1-indexed highest), number of players with score <= his = p + (number of players with same score?) but if distinct, then exactly p players have score >= his? Actually careful: In descending order, highest is position 1. For player at rank k (1-indexed from highest), the number of players with score <= his is (100 - (k-1))? Because there are k-1 players with higher score, and the rest (including himself) have <=? Actually if sorted descending, players with higher score are those with index < k. So players with score <= his are those with index >= k. That count = 100 - (k-1) = 101 - k. For k=2, 101-2=99. For k=11, 101-11=90. So to have at least 90 players <= his, we need 101 - k >= 90 => k <= 11. So top 11 players? But 101-11=90 exactly. So hardcore includes up to the player with rank 11? Actually rank 11 means there are 10 players higher, and 90 players <= (including himself). So that matches f_le=0.9. So hardcore threshold r <= 10? Because r = number of players with strictly higher = k-1. So r <=10. In m=100, t_hardcore=10, so r <=10 includes r=0..10, which corresponds to top 11 players. So hardcore includes r=10 (the 11th highest) as well. So hardcore includes up to r=10. That seems correct.
Now average: f_le >=0.8 => 101 - k >= 80 => k <= 21. So top 21 players. r <=20. So average includes r=0..20. But we have pro and hardcore overlapping? Actually our cascade gives: r <=1 -> pro; else r <=10 -> hardcore; else r <=20 -> average. So for r=2..10 -> hardcore; r=11..20 -> average. That means that r=10 (top 11) is hardcore; r=11 (top 12) is average. So the borderline is at f_le=0.9 for r=10, and f_le=0.89 for r=11? Actually if r=11, then players <= = 100 - 11 = 89, f_le=0.89, which is <0.9 but >=0.8? 0.89 >=0.8, so average. So correct.
Now random: f_le >=0.5 => 101 - k >= 50 => k <= 51. So top 51 players? Actually if k=51, players <= = 101-51=50? Wait compute: if k=51, there are 50 higher players? Actually k=51 means there are 50 players with higher scores, so players <= = 100 - 50 = 50? Actually careful: total 100. Number of players with higher = k-1 = 50. So players with score <= his = 100 - (k-1) = 100 - 50 = 50? That would be f_le=0.5. So to have f_le >=0.5, need 100 - (k-1) >= 50 => k <= 51. So yes, random includes up to rank 51. r <=50. But we also have lower bound r >20? Actually average includes r up to 20. So random includes r=21..50. So top 52? Actually r=50 corresponds to rank 51, f_le=0.5. So random includes that. r=51 would be rank 52? Actually if r=51, then players <= = 49, f_le=0.49, not random. So noob for r>=51. So indeed r=51..99 are noob. That matches thresholds: t_random = m//2 = 50, so random includes r<=50; noob for r>50.
Thus all consistent.
Now we need to confirm that our thresholds using integer division (floor) are exactly correct for these inclusive/exclusive conditions.
Now finalize.
But wait: The problem says "more than 50% of players have better results" for noob. That is f_gt > 0.5. In terms of r, r > 0.5m. For m=4, 0.5m=2, r >2 means r>=3. In our cascade, noob is else (r > t_random). For m=4, t_random = 4//2 = 2. So r >2 gives r>=3, correct.
Now "more than 20% have better results" for random: r > 0.2m. For m=4, 0.2m=0.8, r >0.8 => r>=1. In cascade, random includes r <=2 and r >? Actually we require r > floor(m/5)? But m/5=0.8, floor=0, so random includes r >=1. That's fine.
Now "more than 10% have better results" for average: r > 0.1m. For m=4, 0.1m=0.4, so r >0.4 => r>=1. But average also requires r <=0.2m =0.8? Actually average's upper bound is r <=0.2m. 0.2*m=0.8, so r <=0 => no r. So average empty. In cascade, average requires r <= floor(m/5)=0, but also implicitly r > floor(m/10)=0, so r must be >0 and <=0 -> impossible. So average empty. Good.
Now "more than 1% have better results" for hardcore: r > 0.01m. For m=4, 0.01m=0.04, so r >0.04 => r>=1. But also r <=0.1*m=0.4, so r <=0 => none. So hardcore empty. Cascade: t_hardcore = 0, t_pro=0, so after pro (r=0) else if r <=0 is false for r=1, so hardcore empty. Good.
Now pro: r <=0.01*m => r <=0.04 => r=0 only. So pro for r=0. Good.
Now check case m=1000: thresholds: t_pro = 1000//100 = 10, t_hardcore = 1000//10 = 100, t_average = 1000//5 = 200, t_random = 1000//2 = 500. So:
- r <=10: pro
- 11 <= r <=100: hardcore
- 101 <= r <=200: average
- 201 <= r <=500: random
- r >=501: noob
Now verify proportional: 0.01*m =10, so pro up to r=10 inclusive. Hardcore: r >10 and <=100. So 11-100. Good.
Thus all good.
Now one more nuance: When computing r, we should use strictly greater scores only. That's fine.
Now output: The first line is m. Then each line name and category.
Now code.
I'll provide a clear explanation in the final answer.
But we should consider that the problem might expect the categories in the order: "noob", "random", "average", "hardcore", "pro"? Actually output can be arbitrary, but we can output in any order. Usually they output in alphabetical order? Not required. But we can output in the order we processed dictionary (which is arbitrary). It's fine.
Now let's think about potential pitfalls: The names are guaranteed different, but may appear multiple times. We used dict to store max.
Now time complexity O(n + m^2) which is fine.
Now potential bug: In Python, when iterating over players to compute cnt_better, we do for each i loop over all j. That's O(m^2). m up to 1000, so 1e6 iterations, fine.
Now final code.
But we must ensure we read input correctly: The input might have trailing spaces. Use sys.stdin.read().split().
Now I'll produce final answer.
I will also include comments in code.
Now I'll write final solution. ```python
import sys
def solve() -> None:
data = sys.stdin.read().strip().split()
if not data:
return
it = iter(data)
n = int(next(it))
# dictionary: name -> best score
best = {}
for _ in range(n):
name = next(it)
pts = int(next(it))
# keep the maximum points for each player
if name in best:
if pts > best[name]:
best[name] = pts
else:
best[name] = pts
m = len(best) # number of distinct players
players = list(best.items()) # list of (name, best_score)
# precompute thresholds based on m
t_pro = m // 100 # floor(0.01 * m)
t_hardcore = m // 10 # floor(0.10 * m)
t_average = m // 5 # floor(0.20 * m)
t_random = m // 2 # floor(0.50 * m)
result = []
for name, score in players:
# count players with strictly better score
better = 0
for _, s2 in players:
if s2 > score:
better += 1
# decide category
if better <= t_pro:
cat = "pro"
elif better <= t_hardcore:
cat = "hardcore"
elif better <= t_average:
cat = "average"
elif better <= t_random:
cat = "random"
else:
cat = "noob"
result.append((name, cat))
# output
print(m)
for name, cat in result:
print(name, cat)
if name == "main":
solve()