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

Previous submission (verdict: Time limit exceeded on test 27):
#include <bits/stdc++.h>
// Ujjwal Gupta

using namespace std;

#define int long long int
#define ll long long int
#define pb push_back
using vi = vector<int>;
using vpi = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvs = vector<vector<string>>;
using vc = vector<char>;
using vs = vector<string>;
using si = set<int>;
using ump = unordered_map<int, int>;
using omp = map<int, int>;
using pii = pair<int, int>;
using mpi = map<int, int>;
using mpc = map<char, int>;
using umpc = unordered_map<char, int>;
using maxheap = priority_queue<int>;
using minheap = priority_queue<int, vector<int>, greater<int>>;

#define fe first
#define se second
#define mp make_pair
#define nl cout << "\n";
#define yes cout << "YES" << endl;
#define no cout << "NO" << endl;
#define alice cout << "Alice" << endl;
#define bob cout << "Bob" << endl;
#define mo cout << -1 << " ";
#define zr cout << 0 << " ";
#define ceild(a, b) ((a + b - 1) / b)
#define lb(vec, key) (lower_bound(vec.begin(), vec.end(), key))
#define ub(vec, key) (upper_bound(vec.begin(), vec.end(), key))
#define max3(a, b, c) max(a, max(b, c))
#define max4(a, b, c, d) max(max(a, b), max(c, d))
#define yrn(condition) cout << (condition ? "YES " : "NO ");
#define fa(x, a) for (auto &x : a)
#define fo(i, a, b) for (auto i = a; i < b; ++i)
#define fl(i, a, b) for (auto i = a; i >= b; --i)
#define vsort(v) sort(v.begin(), v.end())
#define revsort(v) sort(v.begin(), v.end(), greater<int>())
#define vmax(a) *max_element(a.begin(), a.end())
#define vmin(a) *min_element(a.begin(), a.end())
#define acc(vec) accumulate(vec.begin(), vec.end(), 0)
#define get_bit(num, i) (((num) >> (i)) & 1)
#define to_lower(s) transform(s.begin(), s.end(), s.begin(), ::tolower)
#define to_upper(s) transform(s.begin(), s.end(), s.begin(), ::toupper)

const int MOD = 1e9 + 7;
int binrec(long long a, long long b) {
    if (b == 0)
        return 1;

    long long res = binrec(a, b / 2);
    res = (1LL * res * res) % MOD;

    if (b & 1)
        return (1LL * a * res) % MOD;

    return res;
}

#define IO ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
bool func(unordered_map<int,int>&mp1,int x1){
    if(x1==0)
    return 0;
    if(mp1.empty()){
        return 0;
    }
    if(mp1.find(x1)!=mp1.end()){
        mp1[x1]--;
        // mp1[x2]--;
        if(mp1[x1]==0){
            mp1.erase(x1);
        }
        return 1;
    }
    int x,y;
      if(x1%2==0){
            x=x1/2;
            y=x1/2;
        }
        else{
            x=x1/2;
            y=x1/2+1;
        }
       if(func(mp1,x)==0|| func(mp1,y)==0)
       return 0;
       return 1;
}
void solve() {
    int n,m;
    cin >> n>>m;
    vi a(n),b(m);
    unordered_map<int,int>mp1,mp2;
    fo(i, 0, n){
        cin>>a[i];
        mp1[a[i]]++;
        
    }
    fo(i,0,m){
        cin>>b[i];
        mp2[b[i]]++;
    }

    for(int i=0;i<m;i++){
        int x,y;
        if(b[i]%2==0){
            x=b[i]/2;
            y=b[i]/2;
        }
        else{
            x=b[i]/2;
            y=b[i]/2+1;
        }
        if(mp1.find(x+y)!=mp1.end()){
             mp1[x+y]--;
                if(mp1[x+y]==0){
                    mp1.erase(x+y);
                }
                continue;
        }
        else{
            if(!func(mp1,x) || !func(mp1,y)){
                cout<<"NO"<<endl;
                return;
            }

            // cout<<"yes"<<endl;
            // return;
            
        }

    }
    if(mp1.size()!=0)
    {
        cout<<"NO"<<endl;
        return ;
    }
    cout<<"YES"<<endl;
    //ujj

    // int ans = 0; 
    
    // cout << ans;
    // nl;
}


signed main() {
    IO;
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}

Submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
// Ujjwal Gupta

using namespace std;

#define int long long int
#define ll long long int
#define pb push_back
using vi = vector<int>;
using vpi = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvs = vector<vector<string>>;
using vc = vector<char>;
using vs = vector<string>;
using si = set<int>;
using ump = unordered_map<int, int>;
using omp = map<int, int>;
using pii = pair<int, int>;
using mpi = map<int, int>;
using mpc = map<char, int>;
using umpc = unordered_map<char, int>;
using maxheap = priority_queue<int>;
using minheap = priority_queue<int, vector<int>, greater<int>>;

#define fe first
#define se second
#define mp make_pair
#define nl cout << "\n";
#define yes cout << "YES" << endl;
#define no cout << "NO" << endl;
#define alice cout << "Alice" << endl;
#define bob cout << "Bob" << endl;
#define mo cout << -1 << " ";
#define zr cout << 0 << " ";
#define ceild(a, b) ((a + b - 1) / b)
#define lb(vec, key) (lower_bound(vec.begin(), vec.end(), key))
#define ub(vec, key) (upper_bound(vec.begin(), vec.end(), key))
#define max3(a, b, c) max(a, max(b, c))
#define max4(a, b, c, d) max(max(a, b), max(c, d))
#define yrn(condition) cout << (condition ? "YES " : "NO ");
#define fa(x, a) for (auto &x : a)
#define fo(i, a, b) for (auto i = a; i < b; ++i)
#define fl(i, a, b) for (auto i = a; i >= b; --i)
#define vsort(v) sort(v.begin(), v.end())
#define revsort(v) sort(v.begin(), v.end(), greater<int>())
#define vmax(a) *max_element(a.begin(), a.end())
#define vmin(a) *min_element(a.begin(), a.end())
#define acc(vec) accumulate(vec.begin(), vec.end(), 0)
#define get_bit(num, i) (((num) >> (i)) & 1)
#define to_lower(s) transform(s.begin(), s.end(), s.begin(), ::tolower)
#define to_upper(s) transform(s.begin(), s.end(), s.begin(), ::toupper)

const int MOD = 1e9 + 7;
int binrec(long long a, long long b) {
    if (b == 0)
        return 1;

    long long res = binrec(a, b / 2);
    res = (1LL * res * res) % MOD;

    if (b & 1)
        return (1LL * a * res) % MOD;

    return res;
}

#define IO ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
bool func(map<int,int>&mp1,int x1){
    if(x1==0)
    return 0;
    if(mp1.empty()){
        return 0;
    }
    if(mp1.find(x1)!=mp1.end()){
        mp1[x1]--;
        // mp1[x2]--;
        if(mp1[x1]==0){
            mp1.erase(x1);
        }
        return 1;
    }
    int x,y;
      if(x1%2==0){
            x=x1/2;
            y=x1/2;
        }
        else{
            x=x1/2;
            y=x1/2+1;
        }
       if(func(mp1,x)==0|| func(mp1,y)==0)
       return 0;
       return 1;
}
void solve() {
    int n,m;
    cin >> n>>m;
    vi a(n),b(m);
    map<int,int>mp1;
    fo(i, 0, n){
        cin>>a[i];
        mp1[a[i]]++;
        
    }
    

    for(int i=0;i<m;i++){
        int x,y;
        if(b[i]%2==0){
            x=b[i]/2;
            y=b[i]/2;
        }
        else{
            x=b[i]/2;
            y=b[i]/2+1;
        }
        if(mp1.find(x+y)!=mp1.end()){
             mp1[x+y]--;
                if(mp1[x+y]==0){
                    mp1.erase(x+y);
                }
                continue;
        }
        else{
            if(!func(mp1,x) || !func(mp1,y)){
                cout<<"NO"<<endl;
                return;
            }

            // cout<<"yes"<<endl;
            // return;
            
        }

    }
    if(mp1.size()!=0)
    {
        cout<<"NO"<<endl;
        return ;
    }
    cout<<"YES"<<endl;
    //ujj

    // int ans = 0; 
    
    // cout << ans;
    // nl;
}


signed main() {
    IO;
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}