|
| 1 | +/* |
| 2 | +ID: Koral Kulacoglu |
| 3 | +TASK: test |
| 4 | +LANG: C++ |
| 5 | +*/ |
| 6 | + |
| 7 | +#include <algorithm> |
| 8 | +#pragma GCC optimize("O3") |
| 9 | +#pragma GCC target("sse4") |
| 10 | + |
| 11 | +#include <bits/stdc++.h> |
| 12 | + |
| 13 | +using namespace std; |
| 14 | + |
| 15 | +typedef long long ll; |
| 16 | +typedef long double ld; |
| 17 | +typedef unsigned long long ull; |
| 18 | +typedef long double lld; |
| 19 | +typedef complex<ld> cd; |
| 20 | + |
| 21 | +typedef pair<int, int> pi; |
| 22 | +typedef pair<ll, ll> pll; |
| 23 | +typedef pair<ld, ld> pld; |
| 24 | + |
| 25 | +typedef vector<int> vi; |
| 26 | +typedef vector<string> vs; |
| 27 | +typedef vector<char> vc; |
| 28 | +typedef vector<ld> vld; |
| 29 | +typedef vector<ll> vll; |
| 30 | +typedef vector<pi> vpi; |
| 31 | +typedef vector<pll> vpll; |
| 32 | +typedef vector<cd> vcd; |
| 33 | + |
| 34 | +template <class T> using pq = priority_queue<T>; |
| 35 | +template <class T> using pqg = priority_queue<T, vector<T>, greater<T>>; |
| 36 | + |
| 37 | +#define FOR(i, a, b) for (int i = a; i < (b); i++) |
| 38 | +#define F0R(i, a) for (int i = 0; i < (a); i++) |
| 39 | +#define FORd(i, a, b) for (int i = (a) - 1; i >= b; i--) |
| 40 | +#define F0Rd(i, a) for (int i = (a) - 1; i >= 0; i--) |
| 41 | +#define trav(a, x) for (auto &a : x) |
| 42 | +#define uid(a, b) uniform_int_distribution<int>(a, b)(rng) |
| 43 | + |
| 44 | +#define sz(x) (int)(x).size() |
| 45 | +#define all(x) x.begin(), x.end() |
| 46 | +#define mp make_pair |
| 47 | +#define pb push_back |
| 48 | +#define fir first |
| 49 | +#define sec second |
| 50 | +#define ins insert |
| 51 | +#define lbound(a, v) lower_bound(all(a), v) - a.begin() |
| 52 | +#define ubound(a, v) upper_bound(all(a), v) - a.begin() |
| 53 | +#define gcd(a, b) __gcd(a, b) |
| 54 | +#define lcm(a, b) (a * b) / gcd(a, b) |
| 55 | + |
| 56 | +template <class T> bool ckmin(T &a, const T &b) { return b < a ? a = b, 1 : 0; } |
| 57 | +template <class T> bool ckmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; } |
| 58 | + |
| 59 | +void __print(int x) { cerr << x; } |
| 60 | +void __print(long x) { cerr << x; } |
| 61 | +void __print(long long x) { cerr << x; } |
| 62 | +void __print(unsigned x) { cerr << x; } |
| 63 | +void __print(unsigned long x) { cerr << x; } |
| 64 | +void __print(unsigned long long x) { cerr << x; } |
| 65 | +void __print(float x) { cerr << x; } |
| 66 | +void __print(double x) { cerr << x; } |
| 67 | +void __print(long double x) { cerr << x; } |
| 68 | +void __print(char x) { cerr << '\'' << x << '\''; } |
| 69 | +void __print(const char *x) { cerr << '\"' << x << '\"'; } |
| 70 | +void __print(const string &x) { cerr << '\"' << x << '\"'; } |
| 71 | +void __print(bool x) { cerr << (x ? "true" : "false"); } |
| 72 | + |
| 73 | +template <typename T, typename V> void __print(const pair<T, V> &x); |
| 74 | +template <typename T> void __print(const T &x) { |
| 75 | + int f = 0; |
| 76 | + cerr << '{'; |
| 77 | + for (auto &i : x) |
| 78 | + cerr << (f++ ? ", " : ""), __print(i); |
| 79 | + cerr << "}"; |
| 80 | +} |
| 81 | +template <typename T, typename V> void __print(const pair<T, V> &x) { |
| 82 | + cerr << '{'; |
| 83 | + __print(x.first); |
| 84 | + cerr << ", "; |
| 85 | + __print(x.second); |
| 86 | + cerr << '}'; |
| 87 | +} |
| 88 | +void _print() { cerr << "]\n"; } |
| 89 | +template <typename T, typename... V> void _print(T t, V... v) { |
| 90 | + __print(t); |
| 91 | + if (sizeof...(v)) |
| 92 | + cerr << ", "; |
| 93 | + _print(v...); |
| 94 | +} |
| 95 | + |
| 96 | +#ifdef DEBUG |
| 97 | +#define dbg(x...) \ |
| 98 | + cerr << __func__ << ":" << __LINE__ << " [" << #x << "] = ["; \ |
| 99 | + _print(x); \ |
| 100 | + cerr << endl; |
| 101 | +#else |
| 102 | +#define dbg(x...) |
| 103 | +#endif |
| 104 | + |
| 105 | +mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); |
| 106 | + |
| 107 | +struct custom_hash { |
| 108 | + size_t operator()(uint64_t x) const { |
| 109 | + x ^= rng(); |
| 110 | + return x ^ (x >> 16); |
| 111 | + } |
| 112 | +}; |
| 113 | + |
| 114 | +const int MOD = 1000000007; |
| 115 | +const char nl = '\n'; |
| 116 | +const int MX = 100001; |
| 117 | + |
| 118 | +void solve() { |
| 119 | + int n, m; |
| 120 | + cin >> n >> m; |
| 121 | + vi a(n); |
| 122 | + FOR(i, 0, n) cin >> a[i]; |
| 123 | + vi b(m); |
| 124 | + FOR(i, 0, m) cin >> b[i]; |
| 125 | + |
| 126 | + if (m * 2 > n) { |
| 127 | + cout << "NO" << nl; |
| 128 | + return; |
| 129 | + } |
| 130 | + |
| 131 | + sort(all(a)); |
| 132 | + sort(all(b)); |
| 133 | + |
| 134 | + vi lessCount(m), moreCount(m); |
| 135 | + for (int i = 0; i < m; i++) { |
| 136 | + int lc = lower_bound(all(a), b[i]) - a.begin(); |
| 137 | + int uc = n - lc; |
| 138 | + lessCount[i] = lc; |
| 139 | + moreCount[i] = uc; |
| 140 | + } |
| 141 | + |
| 142 | + // lessCount will always decrease as we move right |
| 143 | + // we want to minimize our rightCount use |
| 144 | + for (int i = 0; i < m; i++) { |
| 145 | + int remLeft = lessCount[i] - i; |
| 146 | + int remRight = moreCount[i] - (m - i - 1); |
| 147 | + if (remLeft <= 0 || remRight <= 0) { |
| 148 | + cout << "NO" << nl; |
| 149 | + return; |
| 150 | + } |
| 151 | + } |
| 152 | + |
| 153 | + cout << "YES" << nl; |
| 154 | +} |
| 155 | + |
| 156 | +int main() { |
| 157 | + cin.tie(0)->sync_with_stdio(0); |
| 158 | + cin.exceptions(cin.failbit); |
| 159 | + |
| 160 | + int T = 1; |
| 161 | + cin >> T; |
| 162 | + while (T--) { |
| 163 | + solve(); |
| 164 | + } |
| 165 | + |
| 166 | + return 0; |
| 167 | +} |
0 commit comments