Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define _test int _TEST; cin>>_TEST; while(_TEST--)
- #define ff first
- #define ss second
- #define pb push_back
- int main()
- {
- _test
- {
- int n, x;
- cin>>n>>x;
- vector<int> a(n), b(n);
- for(auto &e: a) cin>>e;
- for(auto &e: b) cin>>e;
- vector<pair<int, int>> vp;
- for(int i=0; i<n; i++)
- vp.pb({a[i], i});
- sort(vp.begin(), vp.end());
- sort(b.begin(), b.end());
- vector<int> ans(n);
- int f = 1;
- for(int i=x; i>0; i--)
- {
- ans[vp[n-i].ss] = b[x-i];
- f &= (ans[vp[n-i].ss] < a[vp[n-i].ss]);
- }
- for(int i=x+1, j=0; i<=n; i++, j++)
- {
- ans[vp[j].ss] = b[x+j];
- f &= (ans[vp[j].ss] >= a[vp[j].ss]);
- }
- if(f)
- {
- cout<<"YES\n";
- for(auto e: ans) cout<<e<<" ";
- cout<<"\n";
- }
- else cout<<"NO\n";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment