Let's say the elements of the vector of pairs are
1, 0
2, 0
1, 2
2, 4
4, 0
5, 0
The output should be
1, 2
2, 4
4, 0
5, 0
In the above example, the pairs {1, 0}, and {1, 2} are replaced by the pair {1, 2}, since they share the same first element (1), and the largest second element is (2).
I tried to use set and make the vector unique based on the first element but this doesn't fulfill my second condition.
I suspect that you are trying to do this (in which case nisssh's now-deleted answer should have prior recognition). Efficient? Well, depends what you are actually trying to do ultimately. It would have been better to use a map from the start.
Output:
EDIT If you want to use "sort and unique" (as in cigien's comment) then this would work. Output order may or may not be acceptable.
Output: