The three-prizes problem: decide the rules first
On this page 2 headings
The prize example asks for three high-scoring students, with two extra rules: each should be a subject topper in at least one subject, and the final group should include both genders represented by M and F in the supplied dataset. We must make these rules precise before writing the algorithm.

| Student | CardNo | Gender | Maths | Physics | Chemistry | Total |
|---|---|---|---|---|---|---|
| Rahul | 11 | M | 97 | 92 | 92 | 281 |
| Deepika | 23 | F | 97 | 91 | 88 | 276 |
| Abirami | 18 | F | 72 | 92 | 97 | 261 |
Break a big problem into smaller questions
First decide what “top three in a subject” means when scores tie. Compute the subject cutoffs. Filter the eligible students. Rank their totals while keeping their IDs. Finally check the group rule. For these cards the three winners above qualify and include M and F.
A successful example does not settle every case
What if four students tie at the last prize? What if there is no eligible student from one required category? What if a high-total student misses every subject cutoff? State a tie policy and what to do if the rules cannot all be satisfied. Do not quietly change the criteria after seeing a difficult case.
The lecture’s initial “top three overall, then verify” exploration and its later “filter subject toppers, then rank totals” algorithm agree on our dataset. They can differ on other datasets. Say which rule you intend rather than treating them as universally interchangeable.
Try it yourself
Why keep a student ID with each score?
Show explained answer
A score tells you how high; an ID tells you who earned it.
Try it yourself
Who has the highest actual total?
Show explained answer
Rahul, CardNo 11, with 281.
Try it yourself
Are all three prize winners required to top every subject?
Show explained answer
No. The criterion requires at least one qualifying subject per student.
Try it yourself
Must exactly three valid winners always exist?
Show explained answer
No. Eligibility, representation and tie rules can make the requirements impossible.
