Grand Temple Problem

Is it possible to sort both the elements of pair<int,int>. Sort function on sorts the first element. If i write custom compare.It sorts only the second element. I want to sort both elements.

My code :

To sort both of them, you need to take them in seperate containers. Using custom compare also it is not possible with a single pair.
If you have problem with the approach, follow this Grand temple problem