SHARE
TWEET

Untitled

a guest Oct 21st, 2019 103 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. main(){
  6.     int n,k;
  7.     cin>>n>>k;
  8.     map<int,int> m;
  9.     vector<int> a;
  10.     vector<pair<int,int>> all;
  11.     for(int i=0;i<n;i++){
  12.         int b;
  13.         cin>>b;
  14.         m[b]+=1;
  15.         all.push_back({b,i+1});
  16.         if(m[b]==1)
  17.             a.push_back(b);
  18.     }
  19.     sort(a.begin(),a.end());
  20.     sort(all.begin(),all.end());
  21.     if(a.size()<k){
  22.         cout<<-1;
  23.         return 0;
  24.     }
  25.     int cnt=0;
  26.     int true_cnt=0;
  27.     int i=a.size()-1;
  28.     while(cnt!=k){
  29.         true_cnt+=m[a[i]];
  30.         cnt+=1;
  31.         i-=1;
  32.     }
  33.     vector<int> ans;
  34.     for(int i=n-true_cnt;i>=1;i--){
  35.         ans.push_back(all[i-1].second);
  36.     }
  37.     for(int i=n;i>n-true_cnt;i--){
  38.         ans.push_back(all[i-1].second);
  39.     }
  40.     reverse(ans.begin(),ans.end());
  41.     for(auto i:ans)
  42.         cout<<i<<' ';
  43. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top