Advertisement
georgiy110802

Untitled

Apr 18th, 2022
723
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.45 KB | None | 0 0
  1. main(){
  2.     ios::sync_with_stdio(false);
  3.     cin.tie(0);
  4.     int  n;
  5.     cin >> n;
  6.     vector<pair<int, int>> a(n);
  7.     for(int i = 0; i < n; i++)
  8.     {
  9.         cin >> a[i].first;
  10.         a[i].second = i + 1;
  11.     }
  12.     sort(a.begin(), a.end(), greater<pair<int, int>>());
  13.     int l = 1;
  14.     for(int i = 0; i < n; i++)
  15.     {
  16.         for(; a[i].first > 0 && l < n; l++)
  17.         {
  18.             cout << a[i].second << " " << a[l].second << "\n";
  19.             a[l].first--;
  20.             a[i].first--;
  21.         }
  22.     }
  23. /*7
  24. 3 2 1 2 1 2 1*/
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement