```
class Solution {
public:
vector<pair<int, int>> reconstructQueue(vector<pair<int, int>>& people) {
sort(people.begin(),people.end(),[](pair<int,int>x,pair<int,int>y){return x.first==y.first ? x.second < y.second : x.first > y.first;});
vector<pair<int, int>> res;
for(int i = 0; i < people.size(); ++i) res.insert(res.begin()+people[i].second,people[i]);
return res;
}
};
```