https://www.acmicpc.net/problem/10814
#include <iostream>
#include <utility>
#include <vector>
#include <string>
#include <algorithm>
#include <tuple>
using namespace std;
typedef tuple<int, string, int> T;
bool cmp(T &v1, T &v2)
{
if (get<0>(v1) == get<0>(v2))
return get<2>(v1) < get<2>(v2);
return v1 < v2;
}
int main()
{
vector<T> members;
int N;
cin >> N;
for (int i = 0; i < N; i++)
{
int age;
string name;
cin >> age >> name;
members.push_back(make_tuple(age, name, i));
}
sort(members.begin(), members.end(), cmp);
for (int i = 0; i < N; i++)
cout << get<0>(members[i]) << ' ' << get<1>(members[i]) << '\n';
}