#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
using namespace std;

int main()
{
    pair<int, double> p;
    vector<pair<int, double> > vp;

    p.first = 2;
    p.second = 2.4;
    vp.push_back(p);
    
    p.first = 9;
    p.second = 3.0;
    vp.push_back(p);
    
    p.first = 10;
    p.second = 3.1;
    vp.push_back(p);
    
    p.first = 1;
    p.second = 2.4;
    vp.push_back(p);
    
    p.first = 5;
    p.second = 3.1;
    vp.push_back(p);
    
	cout << "before sort:" << endl;
    for(auto &p : vp) {
		cout << p.first << ", " << p.second << endl;
    }

	sort(vp.begin(), vp.end(),
	    [](const pair<int, double> &p1, const pair<int, double> &p2){
    	    if (p1.second > p2.second) return true;
        	if (p1.second < p2.second) return false;
	        return p1.first < p2.first;
    	}
	);

	cout << endl;
	cout << "after sort:" << endl;

	for(auto &p : vp) {
		cout << p.first << ", " << p.second << endl;
    }
}