Ankit_132

C

Nov 25th, 2023
761
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.06 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define _test   int _TEST; cin>>_TEST; while(_TEST--)
  6. #define ff     first
  7. #define ss     second
  8. #define pb     push_back
  9.  
  10. int main()
  11. {
  12.     _test
  13.     {
  14.         int n, x;
  15.         cin>>n>>x;
  16.  
  17.         vector<int> a(n), b(n);
  18.         for(auto &e: a)     cin>>e;
  19.         for(auto &e: b)     cin>>e;
  20.  
  21.         vector<pair<int, int>> vp;
  22.         for(int i=0; i<n; i++)
  23.             vp.pb({a[i], i});
  24.  
  25.         sort(vp.begin(), vp.end());
  26.         sort(b.begin(), b.end());
  27.  
  28.         vector<int> ans(n);
  29.         int f = 1;
  30.  
  31.         for(int i=x; i>0; i--)
  32.         {
  33.             ans[vp[n-i].ss] = b[x-i];
  34.             f &= (ans[vp[n-i].ss] < a[vp[n-i].ss]);
  35.         }
  36.  
  37.         for(int i=x+1, j=0; i<=n; i++, j++)
  38.         {
  39.             ans[vp[j].ss] = b[x+j];
  40.             f &= (ans[vp[j].ss] >= a[vp[j].ss]);
  41.         }
  42.  
  43.         if(f)      
  44.         {
  45.             cout<<"YES\n";
  46.             for(auto e: ans)        cout<<e<<" ";
  47.             cout<<"\n";
  48.         }
  49.         else       cout<<"NO\n";
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment