Help in Comparator function for Top k most frequent number in stream

Link to my Code : https://ide.codingblocks.com/s/186063
I have sucessfully submitted the problem but i am unable to understand the signs of the compartor function.
Why can’t this work :
struct comp {
bool operator() (const ppi a,const ppi b) {
if(a.S == b.S)
return a.F < b.F;

    return a.S>b.S;       

}
};
As here for Min Heap , we want the smallest of the two numbers when they are of same frequency. So why this is Wrong and reversing the signs lead to correct answer?

Hey @Styagi689 comparator in priority works in opposite fashion, so you write the thing you want the reverse of .
As you can see we are returning a.S<b.S ,instead of a.S>b.S like we would normally do while sorting a vector or an array.

Okay , so as here we are using max heap , so when a.S == b.S (frequency is same) and we return the bigger number , then wouldn’t it be at the top leading to decreasing order of those numbers?

As I said in case of priority queues its comparator is supposed to do opposite of what you want to do actually, so when you are returning the bigger element its keeping them arranged in the opposite order that is increasing order rather than decreasing order

Thank You Sir , got the point .

@Styagi689 you are welcome. Also if you don’t have any further queries please mark the doubt as resolved.