Ankit_132

C

Aug 30th, 2023
342
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.63 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define ll     long long
  6. #define _test   int _TEST; cin>>_TEST; while(_TEST--)
  7.  
  8. int main()
  9. {
  10.     _test
  11.     {
  12.         int n, k;
  13.         cin>>n>>k;
  14.  
  15.         vector<int> a(n);
  16.         for(auto &e: a)
  17.             cin>>e;
  18.  
  19.         set<int> st;
  20.         for(int i=0; i<=n; i++)
  21.             st.insert(i);
  22.  
  23.         for(auto e: a)
  24.             st.erase(e);
  25.  
  26.         a.push_back(*st.begin());
  27.  
  28.         int s = (n+1 - k%(n+1))%(n+1);
  29.  
  30.         for(int i=0; i<n; i++)
  31.         {
  32.             cout<<a[s]<<" ";
  33.             (s += 1) %= (n+1);
  34.         }
  35.         cout<<"\n";
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment