Ready to begin
No records have been processed. Start with Next step.
Now connect the pieces. First compute the third distinct mark level in every subject once. Then call a Boolean procedure on each student: does at least one subject reach its cutoff? Only eligible students enter the total-score ranking.

| Saved cutoff | Value |
|---|---|
| Maths3 | 89 |
| Physics3 | 88 |
| Chemistry3 | 92 |
Procedure SubjectTopper(X, Maths3, Physics3, Chemistry3)
return (X.Mathematics >= Maths3 or
X.Physics >= Physics3 or
X.Chemistry >= Chemistry3)
End Procedure
Maths3 = TopThreeMarks(Scores, "Mathematics")
Physics3 = TopThreeMarks(Scores, "Physics")
Chemistry3 = TopThreeMarks(Scores, "Chemistry")
for each row X in Scores {
if (SubjectTopper(X, Maths3, Physics3, Chemistry3)) {
Insert X.Total and X.CardNo together into the best 3 slots
}
}Read the current record, check the explanation, and watch the variables. Use Back to revisit any step.
Ready
No records have been processed. Start with Next step.
Start at the first step. Watch the current row and the values we remember.
SubjectTopper returns True or False. if (SubjectTopper(...)) has the same effect as comparing that result with True. OR means at least one qualifying subject, not all subjects. A mark exactly equal to the cutoff qualifies because the comparison is >=.
if (X.Total > FirstTotal) {
ThirdTotal = SecondTotal; ThirdID = SecondID
SecondTotal = FirstTotal; SecondID = FirstID
FirstTotal = X.Total; FirstID = X.CardNo
}Use analogous paired moves for insertion into second or third place. An ID of −1 can mark an empty prize slot because all real CardNo values are nonnegative. You could keep IDs alone and look up marks later, but keeping both avoids repeated lookups.
For these cards, the final paired slots are (281,11), (276,23), (261,18): Rahul, Deepika and Abirami. Our lab processes the same supplied records and shows eligibility separately from the running leaders. Subject cutoffs are saved before the ranking scan rather than recomputed inside every visit.
FirstTotal = -1; SecondTotal = -1; ThirdTotal = -1
FirstID = -1; SecondID = -1; ThirdID = -1
for each row X in Scores {
if (SubjectTopper(X, Maths3, Physics3, Chemistry3)) {
v = X.Total
if (v > FirstTotal) {
ThirdTotal = SecondTotal; ThirdID = SecondID
SecondTotal = FirstTotal; SecondID = FirstID
FirstTotal = v; FirstID = X.CardNo
} else if (FirstTotal > v and v > SecondTotal) {
ThirdTotal = SecondTotal; ThirdID = SecondID
SecondTotal = v; SecondID = X.CardNo
} else if (SecondTotal > v and v > ThirdTotal) {
ThirdTotal = v; ThirdID = X.CardNo
} else {
Record any equality with a retained score for tie review
}
}
}
Check the selected IDs, representation rule and any boundary ties
before declaring the final prize winners.This expands the source’s strict-comparison update template. Equal totals do not create another distinct total level in that template. A general three-student award algorithm must retain tied candidates or apply its stated tie policy; do not assume these strict comparisons alone resolve ties. Our supplied final winning totals are distinct.
Does a mark equal to a cutoff qualify?
Yes. Use >=, not >.
Why is OR appropriate in SubjectTopper?
The rule asks for a qualifying mark in at least one subject.
What happens if you move SecondTotal but forget SecondID?
The score can become attached to the wrong person.
Does SubjectTopper know that its thresholds are third distinct marks?
No. It simply compares against the values passed to it. The caller is responsible for computing the intended thresholds.
Why compute the thresholds before the main loop?
They stay fixed for every student and avoid repeatedly scanning the dataset for the same information.