Can anybody explain me this code of tourist from yesterday's contest?
Difference between en1 and en2, changed 86 character(s)
[Problem link](https://codeforces.com/contest/1375/problem/E)<br>↵

<spoiler summary="Tourist Code">↵
~~~~~↵
/**↵
 *    author:  tourist↵
 *    created: 04.07.2020 18:34:48       ↵
**/↵
#include <bits/stdc++.h>↵

using namespace std;↵

int main() {↵
  ios::sync_with_stdio(false);↵
  cin.tie(0);↵
  int n;↵
  cin >> n;↵
  vector<int> a(n);↵
  for (int i = 0; i < n; i++) {↵
    cin >> a[i];↵
  }↵
  vector<int> b(n);↵
  iota(b.begin(), b.end(), 0);↵
  sort(b.begin(), b.end(), [&](int i, int j) {↵
    if (a[i] != a[j]) {↵
      return a[i] < a[j];↵
    }↵
    return i < j;↵
  });↵
  vector<pair<int, int>> ret;↵
  for (int it = 0; it < n; it++) {↵
    for (int i = 0; i < n - 1; i++) {↵
      if (b[i] > b[i + 1]) {↵
        ret.emplace_back(b[i + 1], b[i]);↵
        swap(b[i], b[i + 1]);↵
      }↵
    }↵
  }↵
  cout << ret.size() << '\n';↵
  for (auto& p : ret) {↵
    cout << p.first + 1 << " " << p.second + 1 << '\n';↵
  }↵
  return 0;↵
}↵

~~~~~↵
</spoiler>↵

What I do not understand is how after finding array b we get the correct answer.<br>↵
Thanks in advance.↵

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en2 English Rock2000 2020-07-05 14:58:59 86 Tiny change: ' b we get correct a' -> ' b we get the correct a'
en1 English Rock2000 2020-07-05 14:57:14 1062 Initial revision (published)