Advertisement
Ahmed_Negm

Untitled

Jul 22nd, 2022
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.08 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define ll long long
  5. #define ull unsigned long long
  6. #define nl '\n'
  7. #define sz(x) int(x.size())
  8. #define all(x) x.begin(),x.end()
  9. #define rall(s)  s.rbegin(), s.rend()
  10. #define getline(s) getline(cin>>ws,s)
  11. #define ceill(n, m) (((n) / (m)) + ((n) % (m) ? 1 : 0))
  12. #define pi  3.141592653589793
  13.  
  14. /*
  15. ███╗░░██╗███████╗░██████╗░███╗░░░███╗
  16. ████╗░██║██╔════╝██╔════╝░████╗░████║
  17. ██╔██╗██║█████╗░░██║░░██╗░██╔████╔██║
  18. ██║╚████║██╔══╝░░██║░░╚██╗██║╚██╔╝██║
  19. ██║░╚███║███████╗╚██████╔╝██║░╚═╝░██║
  20. ╚═╝░░╚══╝╚══════╝░╚═════╝░╚═╝░░░░░╚═╝
  21.  
  22. */
  23.  
  24. void Fast_IO(){
  25. ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  26. // freopen("filename.in", "r", stdin), freopen("filename.txt", "w", stdout);
  27. #ifndef ONLINE_JUDGE
  28. freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
  29. #endif
  30. }
  31.  
  32.  
  33. bool comp(pair<ll,ll>&a,pair<ll,ll>&b){
  34.     if(a.first==b.first) return a.second<b.second;
  35.     return a.first<b.first;
  36. }
  37.  
  38.  
  39. void solve(){
  40.   ll n; cin>>n;
  41.   vector<pair<ll,ll>>v;
  42.   for(int i=1; i<=n; i++){
  43.       ll x; cin>>x;
  44.       v.push_back({x,i});
  45.   }
  46.   sort(all(v),comp);
  47.   vector<ll>res;
  48.     while(1){
  49.     auto maxe = *max_element(all(v));
  50.         if(maxe.first==0) break;
  51.         for(int i=0; i<n; i++){
  52.         if(v[i].first==maxe.first){
  53.         res.push_back(v[i].second);
  54.         v[i].first--;
  55.         break;
  56.         }
  57.         }
  58.  
  59.     }
  60.     for(int i=1; i<sz(res); i++){
  61.         if(res[i] == res[i-1]) return void(cout<<"-1");
  62.     }
  63.     for(auto&i:res) cout<<i<<' ';
  64.  
  65.  
  66.  
  67.  
  68.  
  69.     }
  70.  
  71. int main(){
  72.     Fast_IO();
  73. int t =1;
  74. //cin>>t;
  75. while(t--){
  76. solve();
  77. }
  78. return 0;
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement