...
vector<int> a = {5, 3, 1, 3};
vector<int> b = {6, 1, 7, 2};
vector<int> indexes = {0, 1, 2, 3};
sort(indexes.begin(), indexes.end(), [&a, &b](int x, int y) -> bool {
vector<int> ind = {0, 1, 2, 3};
sort(ind.begin(), ind.end(), [&a, &b](int x, int y) -> bool {
return a[x] < a[y] || (a[x] == a[y] && b[x] < b[y]);
});
for (int i: ind) {
cout << a[i] << " " << b[i] << endl;
}
==
(Often, a cleaner alternative to lambda functions is defining a class holding all the data needed for sorting and providing an implementation for the $<$ operator.)