Advertisement
pb_jiang

CF1894D

Mar 27th, 2025
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.26 KB | None | 0 0
  1. // Problem: D. Neutral Tonality
  2. // Contest: Codeforces - Codeforces Round 908 (Div. 2)
  3. // URL: https://codeforces.com/problemset/problem/1894/D
  4. // Memory Limit: 512 MB
  5. // Time Limit: 3000 ms
  6. //
  7. // Powered by CP Editor (https://cpeditor.org)
  8.  
  9. #include <assert.h>
  10. #include <bits/stdc++.h>
  11. using namespace std;
  12. #ifndef __DEBUG__
  13. #define dbg(...) 42
  14. #endif
  15. template <class T> using mpq = priority_queue<T, vector<T>, greater<T>>;
  16.  
  17. using ll = long long;
  18. using a2l = array<ll, 2>;
  19. using pll = pair<ll, ll>;
  20. using vl = vector<ll>;
  21.  
  22. void solve()
  23. {
  24.     ll n, m;
  25.     cin >> n >> m;
  26.     vl a(n), b(m), dp(n, LLONG_MAX), c;
  27.     for (auto &x : a)
  28.         cin >> x;
  29.     for (auto &x : b)
  30.         cin >> x;
  31.     ranges::sort(b);
  32.  
  33.     for (auto x : a) {
  34.         auto it = lower_bound(dp.begin(), dp.end(), x);
  35.         while (b.empty() == false && b.back() >= x) {
  36.             c.push_back(b.back());
  37.             b.pop_back();
  38.         }
  39.         *it = x;
  40.         c.push_back(x);
  41.     }
  42.     while (b.empty() == false) {
  43.         c.push_back(b.back());
  44.         b.pop_back();
  45.     }
  46.     for (auto x : c)
  47.         cout << x << ' ';
  48.     cout << '\n';
  49. }
  50.  
  51. int main(int argc, char **argv)
  52. {
  53.     ll t;
  54.     cin >> t;
  55.     while (t--)
  56.         solve();
  57.     return 0;
  58. };
  59.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement