Problem: 2061D - Kevin and Numbers
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 3):
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define mod 1000000007

void solve()
{
    int n, m;
    cin >> n >> m;
    priority_queue<int> pq1, pq2;
    for (int i = 0; i < n; i++)
    {
        int x;
        cin >> x;
        pq1.push(x);
    }
    for (int i = 0; i < m; i++)
    {
        int x;
        cin >> x;
        pq2.push(x);
    }
    int count = 0;
    while (!pq1.empty() && !pq2.empty() && count <= n - m)
    {
        int num1 = pq1.top();
        int num2 = pq2.top();
        pq1.pop();
        pq2.pop();
        // cout << num1 << " " << num2 << endl;
        if (num1 == num2)
            continue;
        else
        {
            count++;
            if (num2 % 2)
            {
                pq2.push(num2 / 2);
                pq2.push((num2 + 1) / 2);
            }
            else
            {
                pq2.push(num2 / 2);
                pq2.push(num2 / 2);
            }
            pq1.push(num1);
        }
    }
    if (pq1.empty() && pq2.empty())
    {
        cout << "Yes" << endl;
    }
    else
        cout << "No" << endl;
}
#undef int
int main()
{
    cin.tie(0)->sync_with_stdio(0);
    int t;
    cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}

Submission (verdict: Time limit exceeded on test 6):
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

template <typename T>
using ordered_set =
    __gnu_pbds::tree<T, __gnu_pbds::null_type, less<T>, __gnu_pbds::rb_tree_tag,
    __gnu_pbds::tree_order_statistics_node_update>;
using pi = pair<int, int>;
using pl = pair<long long, long long>;
using vi = vector<int>;
using vl = vector<long long>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<long long>>;
using vpi = vector<pair<int, int>>;
using vpl = vector<pair<long long, long long>>;
using vvpi = vector<vector<pair<int, int>>>;
using vvpl = vector<vector<pair<long long, long long>>>;
using vb = vector<bool>;
using vs = vector<string>;
using si = set<int>;
using mpii = map<int, int>;

#define fori(i, a, b) for (int i = a; i < b; ++i)
#define fore(i, a, b) for (int i = a; i <= b; ++i)
#define forr(i, a, b) for (int i = a; i > b; --i)
#define forre(i, a, b) for (int i = a; i >= b; --i)

#define pb push_back
#define sc static_cast
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define sz(x) (int32_t)x.size()
#define yes cout << "YES\n";
#define no cout << "NO\n";
#define approx(a) fixed << setprecision(a)
#define ff first
#define ss second
#define INF LONG_LONG_MAX
#define INFF LONG_LONG_MIN
#define inf INT_MAX
#define inff INT_MIN
#define nl '\n'

template <class T> void read(vector<T> &v);
template <class F, class S> void read(pair<F, S> &p);
template <class T, size_t Z> void read(array<T, Z> &a);
template <class T> void read(T &x) {
	cin >> x;
}
template <class R, class... T> void read(R &r, T &...t) {
	read(r);
	read(t...);
};
template <class T> void read(vector<T> &v) {
	for (auto &x : v)
		read(x);
}
template <class F, class S> void read(pair<F, S> &p) {
	read(p.ff, p.ss);
}
template <class T, size_t Z> void read(array<T, Z> &a) {
	for (auto &x : a)
		read(x);
}

template <class F, class S> void pr(const pair<F, S> &x);
template <class T> void pr(const T &x) {
	cout << x;
}
template <class R, class... T> void pr(const R &r, const T &...t) {
	pr(r);
	pr(t...);
}
template <class F, class S> void pr(const pair<F, S> &x) {
	pr("{", x.ff, ", ", x.ss, "}");
}
void ps() {
	pr("\n");
}
template <class T> void ps(const T &x) {
	pr(x);
	ps();
}
template <class T> void ps(vector<T> &v) {
	for (auto &x : v)
		pr(x, ' ');
	ps();
}
template <class T, size_t Z> void ps(const array<T, Z> &a) {
	for (auto &x : a)
		pr(x, ' ');
	ps();
}
template <class F, class S> void ps(const pair<F, S> &x) {
	pr(x.ff, ' ', x.ss);
	ps();
}
template <class R, class... T> void ps(const R &r, const T &...t) {
	pr(r, ' ');
	ps(t...);
}

#define definp()                                                               \
  int n;                                                                       \
  read(n);                                                                     \
  vl a(n);                                                                     \
  read(a);
#define int long long

void exec_once() {
}
bool tc = 1;
#define MOD (long long)(1e9 + 7)
bool fx(mpii &mp, int x, int n){
   if(mp[x] >= 1){
       mp[x]--;
       return true;
   } 
   bool f1 = 0, f2 = 0;
   if(mp[x/2] >= n){
       f1 = 1;
       mp[x/2] -= n;
   }
   else {
       int xx = mp[x/2];
       mp[x/2]=0;
       if(x!=x/2){
       //ps("calling",x/2,"need",n-xx);
        f1 = fx(mp, x/2, n-xx);
       }
   }
   if(mp[(x+1)/2] >= n){
       f2 = 1;
       mp[(x+1)/2] -= n;
   }
   else {
       int xx = mp[(x+1)/2];
       mp[(x+1)/2]=0;

       if(x != (x+1)/2){
       //ps("calling",(x+1)/2,"need",n-xx);

       f2 = fx(mp, (x+1)/2, n-xx);
       }
   }
    return f1 && f2;
}
void solve(int tn [[maybe_unused]]) {
	int n, m;
	read(n,m);
	vl b(m);
	mpii mp;
	int s2 = 0;
	fori(i,0,n) {
		int x;
		read(x);
		mp[x]++;
		s2+=x;
	}
	read(b);
	sort(all(b));
	int s1 = accumulate(all(b), 0LL);
    if(s1!=s2)return ps("NO");	
	fori(i,0,m) 
	    if(!fx(mp, b[i], 1)) return ps("NO");


	ps("YES");

}

int32_t main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	exec_once();
	int t = 1;
	if (tc)
		cin >> t;
	fore(tn, 1, t) solve(tn);
	return 0;
}