Problem: 2061D - Kevin and Numbers
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Time limit exceeded on test 17):
#pragma GCC optimize("O3,unroll-loops")
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#include <functional>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <ios>
#include <map>
#include <string>
#include <queue>
#include <vector>
#include <stack>
#include <set>
using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;
const int MOD = 1e9+7;

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

    ll tt = 1;
    cin >> tt;
    while (tt--) {
        auto solve = [&]()
        {
            ll n, m, k, x, y;
            
            cin>>n>>m;
            multiset<ll> a;
            vector<ll> b;

            for (int i = 0; i < n; i++) {
                cin>>x;
                a.insert(x);
            }

            for (int i = 0; i < m; i++) {
                cin>>x;
                b.push_back(x);
            }

            auto f = [&] (ll  x, auto &&f) -> bool {
                if(a.count(x)) {
                    a.erase(a.find(x));
                    return true;
                }
                else if(!a.size()) return false;
                else if(*a.begin()>x) return false;
                else return f(x/2, f)&& f(x-x/2, f);
            };

            bool ok = true;
            for (int i = 0; i < m; i++) {
                if(!f(b[i], f)) {
                    ok = false;
                    break;
                }
            }
            
            if(a.size()) ok = false;
            cout<<(ok ? "YES" : "NO");


            cout<<endl;
        };
        solve();
    }
    return 0;
}

Submission (verdict: Time limit exceeded on test 17):
#pragma GCC optimize("O3,unroll-loops")
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#include <functional>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <ios>
#include <map>
#include <string>
#include <queue>
#include <vector>
#include <stack>
#include <set>
using namespace std;

typedef int ll;
typedef pair<ll, ll> pll;
const int MOD = 1e9+7;

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

    ll tt = 1;
    cin >> tt;
    while (tt--) {
        auto solve = [&]()
        {
            ll n, m, k, x, y;
            
            cin>>n>>m;
            multiset<ll> a;
            vector<ll> b;

            for (int i = 0; i < n; i++) {
                cin>>x;
                a.insert(x);
            }

            for (int i = 0; i < m; i++) {
                cin>>x;
                b.push_back(x);
            }

            auto f = [&] (ll x, auto &&f) -> bool {
                if(a.count(x)) {
                    a.erase(a.find(x));
                    return true;
                }
                else if(!a.size()) return false;
                else if(*a.begin()>x) return false;
                else return f(x/2, f)&& f(x-x/2, f);
            };

            bool ok = true;
            for (int i = 0; i < m; i++) {
                if(!f(b[i], f)) {
                    ok = false;
                    break;
                }
            }
            if(a.size()) ok = false;
            cout<<(ok ? "YES" : "NO");


            cout<<endl;
        };
        solve();
    }
    return 0;
}