❓ The question first
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.
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
One line per winner, exactly in this format:
Yodeller 5 is the TopYodeller: score 996, worst rank 5
🎬 The solution, step by step
- Keep a running total per yodeller; add each round's scores.
- After each round, compute every rank by counting how many totals are strictly higher — that one rule handles ties automatically.
- Keep a
worst[i]per yodeller, updated every round — for EVERYONE, because the winner is only known at the end.
💻 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
worst for every yodeller from round 1, then read off the winner's at the end.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).✋ 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.