Help needed in defining sorting comparator for a pair

Правка en1, от code_warrior, 2020-09-05 06:53:55

Hello,friends. Recently, I was solving a problem Two Platformswhich required sorting the pairs in such a way that the elements with the smaller value of second element is sorted earlier and if the the second element of two pairs are same then the element with smaller value of first element is sorted earlier, I just want to ask what should be our comparator for this.

Wrong Answer with first compartor Right Answer with comparator of second type

Should it be like:

bool comp(pair<ll,ll>a,pair<ll,ll>b) { return a.second<b.second; }

or

bool comp(pair<ll,ll>a,pair<ll,ll>b) { if(a.second==b.second) return a.first<b.first;

return a.second<b.second; }

Well, when i tried submitting my code with the first comparator and it gave me the wrong result but with the second one everything worked fine.Can someone explain his idea about this.

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en2 Английский code_warrior 2020-09-05 06:54:15 4 Tiny change: '1904498)\n[Right A' -> '1904498)\n\n\n[Right A'
en1 Английский code_warrior 2020-09-05 06:53:55 1098 Initial revision (published)