Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Problem: D. Neutral Tonality
- // Contest: Codeforces - Codeforces Round 908 (Div. 2)
- // URL: https://codeforces.com/problemset/problem/1894/D
- // Memory Limit: 512 MB
- // Time Limit: 3000 ms
- //
- // Powered by CP Editor (https://cpeditor.org)
- #include <assert.h>
- #include <bits/stdc++.h>
- using namespace std;
- #ifndef __DEBUG__
- #define dbg(...) 42
- #endif
- template <class T> using mpq = priority_queue<T, vector<T>, greater<T>>;
- using ll = long long;
- using a2l = array<ll, 2>;
- using pll = pair<ll, ll>;
- using vl = vector<ll>;
- void solve()
- {
- ll n, m;
- cin >> n >> m;
- vl a(n), b(m), dp(n, LLONG_MAX), c;
- for (auto &x : a)
- cin >> x;
- for (auto &x : b)
- cin >> x;
- ranges::sort(b);
- for (auto x : a) {
- auto it = lower_bound(dp.begin(), dp.end(), x);
- while (b.empty() == false && b.back() >= x) {
- c.push_back(b.back());
- b.pop_back();
- }
- *it = x;
- c.push_back(x);
- }
- while (b.empty() == false) {
- c.push_back(b.back());
- b.pop_back();
- }
- for (auto x : c)
- cout << x << ' ';
- cout << '\n';
- }
- int main(int argc, char **argv)
- {
- ll t;
- cin >> t;
- while (t--)
- solve();
- return 0;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement