Runtime error in CSES Simple question

There is this simple question of CSES sorting and searching. CSES Problem

I figured out the logic to sort by end and just take the maximum possible set formed, basically greedy :slight_smile: I have coded this and got all AC but just one RE. I looked up but didn’t found why it got RE. Input length is not an issue. As there is a similar input of that type. My solution
Please point out my mistake as I am not able to figure it out.

“In C++, comparator should return false,if the arguments are equal.”
Otherwise u will get errors.So, instead of “<=” use “<” in ur comparator.

So,the comparator should be-

bool compare(const pair<int, int>& a, const pair<int, int>& b){
    if(a.second < b.second) return true;
    return false;
}
1 Like

Thank you I got AC.

1 Like

you’re welcome.