Please help in debugging my submission in Atcoder Beginner Contest 260

Hi, The question is this ABC 260 — B. I can not find a flaw in my submission. The failing test cases are not available.

Please find the flaw. Thanking in advance.

Still unsolved

It would help if you gave some more information

The error lies in the way you are sorting. For example, when you try to find the best math score, you call:

sort(v.begin(), v.end(), restoreOrig); //restores original v
sort(v.begin(), v.end(), compMath);
bool compMath(Obj i1, Obj i2){
    return i1.math > i2.math;

But the problem clearly says that ties are “broken by examinees’ numbers”. Meaning if you have 2 math scores with 80, the one with the lower index will be admitted. You ignore examinees numbers, though.

sort() in c++ does not keep relative order of equal elements. Meaning you either need another compMath-function or another sorting algorithm. Using stable_sort() instead of sort() would, for example, AC your submission.