CCC 2004 · SENIOR S2 · SORTING & RANKING

TopYodeller

A singing contest with cumulative scores. Track everyone's rank after every round — the winner's WORST moment is part of the answer.

❓ The question first

❓ THE QUESTION

Problem — TopYodeller

n yodellers compete over k rounds. After each round, every yodeller's score for that round is added to their total, and ranks are assigned from the totals: a yodeller's rank is j + 1 if exactly j yodellers have a higher total (ties share a rank). For the yodeller with the highest total at the end, print their number, their total score, and their worst (largest) rank at any point in the competition. If several tie for first, print one line per winner, in increasing contestant number.

Input

First line: n (yodellers) and k (rounds). Then k lines, each with n integers — every yodeller's score in that round, in contestant order. Scores may be negative.

5 2
99 97 100 85 -4
95 97 100 62 1000
Output

One line per winner, exactly in this format:

Yodeller 5 is the TopYodeller: score 996, worst rank 5

🎬 The solution, step by step

The idea — totals, ranks, and a memory for worst ranks:
  1. Keep a running total per yodeller; add each round's scores.
  2. After each round, compute every rank by counting how many totals are strictly higher — that one rule handles ties automatically.
  3. Keep a worst[i] per yodeller, updated every round — for EVERYONE, because the winner is only known at the end.
Animation — walk the official sample

💻 The code

line = input().split()
n = int(line[0])              # yodellers
k = int(line[1])              # rounds

totals = [0] * n
worst = [0] * n               # worst rank seen, per yodeller

for _ in range(k):
    scores = list(map(int, input().split()))
    for i in range(n):
        totals[i] += scores[i]
    for i in range(n):
        rank = 1 + sum(1 for t in totals if t > totals[i])
        if rank > worst[i]:
            worst[i] = rank

best = max(totals)
for i in range(n):
    if totals[i] == best:
        print(f"Yodeller {i + 1} is the TopYodeller: score {totals[i]}, worst rank {worst[i]}")

⭐ Key points & traps

Trap 1 — ranks by sorting positions: if you sort and use positions, the two 194s in round 2 get ranks 3 and 4 — wrong. The rule is 1 + count of strictly higher totals, which gives both 3, and the next yodeller 5, not 4.
Trap 2 — tracking only the current leader's worst rank: the leader changes (here, at the last round). Track worst for every yodeller from round 1, then read off the winner's at the end.
Exact output matters: the line is Yodeller 5 is the TopYodeller: score 996, worst rank 5 — one 'l' in Yodeller, no period, contestant numbers count from 1 while your list counts from 0 (i + 1).
Negative scores are real: round 1 contains a −4. Nothing in the solution may assume scores are positive — totals and max() handle negatives naturally.

✋ Your turn — predict first, then check

Tiny case: input 2 1 then 10 20. What prints?

One round: totals 10, 20; ranks 2, 1. Winner is #2 with 20, and his only rank was 1, so: Yodeller 2 is the TopYodeller: score 20, worst rank 1.