-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCF1896C.cpp
41 lines (41 loc) · 1.3 KB
/
CF1896C.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <bits/extc++.h>
using namespace std;
namespace pbds = __gnu_pbds;
using ui = unsigned int;
using uli = unsigned long long int;
using li = long long int;
int main(void) {
ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
size_t T;
cin >> T;
while (T--) {
size_t n, m;
cin >> n >> m;
vector<pair<ui, size_t>> a(n), b(n);
for (size_t i = 0; i < n; ++i) cin >> a[i].first, a[i].second = i;
for (size_t i = 0; i < n; ++i) cin >> b[i].first;
sort(a.begin(), a.end());
sort(b.begin(), b.end());
vector<pair<ui, size_t>> c(b.begin(), b.begin() + m);
b.erase(b.begin(), b.begin() + m);
b.insert(b.end(), c.begin(), c.end());
for (size_t i = 0; i < n; ++i) b[i].second = a[i].second;
sort(a.begin(), a.end(),
[](pair<ui, size_t> const& a, pair<ui, size_t> const& b) {
return a.second < b.second;
}),
sort(b.begin(), b.end(),
[](pair<ui, size_t> const& a, pair<ui, size_t> const& b) {
return a.second < b.second;
});
size_t cnt = 0;
for (size_t i = 0; i < n; ++i) cnt += a[i].first > b[i].first;
if (cnt == m) {
cout << "YES\n";
for (size_t i = 0; i < n; ++i) cout << b[i].first << ' ';
cout << '\n';
} else
cout << "NO\n";
}
return 0;
}