If I have a map<string,pair<int,int>> and I want to sort it in three different ways. 1.Sort by key. 2.Sort by value of first element in the pair. 3.Sort by value of second element in the pair.

Example : if mp [ {a,{9,7}} {y,{2,5}} {g,{3,1}} {i,{6,6}} {e,{1,2}} ]

**1.Sort by key:**

**2.Sort by value of first element in the pair:**

**3.Sort by value of second element in the pair:**

Elements in the map are sorted by default by the key.

you can't change its order

Then how do I sort the list?

use a vector<pair<string,pair<int,int>>>

Using vector<tuple<string, int, int>> is working fine for me with custom comparator. Thanks for the help though

I think you are writing this post after thinking implementation of Div3 B2 Problem. Am I right ? Yes I am also trying to get the same answer I will be following this post to get those answer. : — )

NO there was a question related to this in my Amazon exam.

Hello! I would recommend you implementing by this way, by vector of pairs and comparators. The link: https://pastebin.com/f2bUv82W. I hope that I helped you.

Really helpful thanks!!

hey can someone help me with this problem? https://codeforces.com/contest/143/problem/A this is my solution https://pastebin.com/ViwFKvWP

You should make your own post describing in short:

Instead of having this convoluted of a data structure, try to come up with a better way of implementing all around.

Check out my solution . its simple than u r thinking, MY IMPLEMENTATION for problem 1551 B2 any suggestions to make my solution cleaner are appreciated