v 0. Pasted by slipstak2 as cpp at 2015-01-23 05:33:30 MSK and set expiration to never.

Paste will expire never.

  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4.  
  5. using namespace std;
  6.  
  7. int n;
  8. vector<int> inv;
  9. vector<int> ans;
  10. int main() {
  11. #ifdef _DEBUG
  12.     freopen("input.txt","r",stdin);
  13.     freopen("output.txt","w",stdout);
  14. #endif
  15.  
  16.     cin>>n;
  17.     inv.resize(n);
  18.     ans.resize(n);
  19.     for (int i = 0; i < n; ++i) {
  20.         cin>>inv[i];
  21.     }
  22.     int num = n;
  23.     for (int i = 0; i < n; ++i) {
  24.         int pos = n - 1 - (find(inv.rbegin(), inv.rend(), 0) - inv.rbegin());
  25.         ans[pos] = num--;
  26.         inv[pos] = -1;
  27.         for (int j = pos + 1; j < n; ++j) {
  28.             inv[j]--;
  29.         }
  30.     }
  31.  
  32.     for (int i = 0; i < n; ++i) {
  33.         cout << ans[i] << ' ';
  34.     }
  35.    
  36.     return 0;
  37. }


Editing is locked.