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
#define YES cout<<"YES\n";
#define NO cout<<"NO\n";
#define endl "\n"
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
const int N=1e9+7;
const int N1=1e6+3;
signed main(){IOS;
    int t;cin>>t;
    while(t--){
        int n,m;cin>>n>>m;int a[n+1],b[m+1];
        map<int,int>mp;int sum1=0,sum2=0;
        for(int i=1;i<=n;i++){
            cin>>a[i];mp[a[i]]++;sum1+=a[i];
        }
        for(int i=1;i<=m;i++)cin>>b[i],sum2+=b[i];
        if(sum1!=sum2){
            cout<<"No"<<endl;continue;
        }
        sort(b+1,b+m+1);
        auto dfs=[&](auto &dfs,int x)->int{
            if(mp[x]){
               mp[x]--;return 1;
            }
            if(!x)return 0;
            if(x%2==0)return dfs(dfs,x/2)&&dfs(dfs,x/2);
            else return dfs(dfs,x/2)&&dfs(dfs,x/2+1);
        };
        int flag=1;
        for(int i=m;i>=1;i--){
            if(mp[b[i]])mp[b[i]]--;
            else{
                flag=dfs(dfs,b[i]);
            }
        }
        if(flag)cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
}
/*******************************************
............................................
............................................
............................................
............................................
.............................1ffLf1.........
............................GGGGGGGC........
....................8CCCftCCCCC1;LLG,.......
..................:CC8CCC.CCCCCCii..........
.................CC88CCCC.CCCCCCC...........
................CC88CCCCC .8.:8CCC..........
................888 CCCCC.88888G;;,.........
,................888CC88.888888888,.........
:::...............CCC888.888888888..........
:::::............Gi1tC8f888888C88,..........
:::::::,........111tttfffffLG8888...........
:::::::::,....ii111ttttttfffttG.............
::::::::::::i111tttffffffffffttt............
::::::::::11tttttfff....fffffftt ...........
..:::::::1Lf1tff,..........fffff1...........
....,:::iiftG::::::.........,LLGtL..........
::::::;:i11t:;;;;;;::,,,,,,,,, f1ii,::,,,,,,
::::::::i11t:::::::::::::::::::f111:::::::::
::::::::111:::::::::::::::::::::t111::::::::
:::::::i1if::::::,,,,,,,,,,,,,,:i111::::::,:
,,,,,::,8G,,,,,,,,,,,,,,,,,,,,,,,tL1:,,,,,,,
,,,,,,:LGL;,,,,,,,,,,,,,,,,,,,,,,,CLf,,,,,,,
,,,,,;LGGG,,,,:,,,,,,,,,,,,,,,,,,,LGCG,,,,,,
*******************************************/

Submission (verdict: Accepted):
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define YES cout<<"YES\n";
#define NO cout<<"NO\n";
#define endl "\n"
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
const int N=1e9+7;
const int N1=1e6+3;
signed main(){IOS;
    int t;cin>>t;
    while(t--){
        int n,m;cin>>n>>m;int a[n+1],b[m+1];
        map<int,int>mp;int sum1=0,sum2=0;
        for(int i=1;i<=n;i++){
            cin>>a[i];mp[a[i]]++;sum1+=a[i];
        }
        for(int i=1;i<=m;i++)cin>>b[i],sum2+=b[i];
        if(sum1!=sum2){
            cout<<"No"<<endl;continue;
        }
        sort(b+1,b+m+1);
        auto dfs=[&](auto &dfs,int x)->int{
            if(mp[x]){
               mp[x]--;return 1;
            }
            if(!x)return 0;
            if(x%2==0)return dfs(dfs,x/2)&&dfs(dfs,x/2);
            else return dfs(dfs,x/2)&&dfs(dfs,x/2+1);
        };
        int flag=1;
        for(int i=m;i>=1;i--){
            if(mp[b[i]])mp[b[i]]--;
            else{
                flag=dfs(dfs,b[i]);
                if(!flag)break;
            }
        }
        if(flag)cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
}
/*******************************************
............................................
............................................
............................................
............................................
.............................1ffLf1.........
............................GGGGGGGC........
....................8CCCftCCCCC1;LLG,.......
..................:CC8CCC.CCCCCCii..........
.................CC88CCCC.CCCCCCC...........
................CC88CCCCC .8.:8CCC..........
................888 CCCCC.88888G;;,.........
,................888CC88.888888888,.........
:::...............CCC888.888888888..........
:::::............Gi1tC8f888888C88,..........
:::::::,........111tttfffffLG8888...........
:::::::::,....ii111ttttttfffttG.............
::::::::::::i111tttffffffffffttt............
::::::::::11tttttfff....fffffftt ...........
..:::::::1Lf1tff,..........fffff1...........
....,:::iiftG::::::.........,LLGtL..........
::::::;:i11t:;;;;;;::,,,,,,,,, f1ii,::,,,,,,
::::::::i11t:::::::::::::::::::f111:::::::::
::::::::111:::::::::::::::::::::t111::::::::
:::::::i1if::::::,,,,,,,,,,,,,,:i111::::::,:
,,,,,::,8G,,,,,,,,,,,,,,,,,,,,,,,tL1:,,,,,,,
,,,,,,:LGL;,,,,,,,,,,,,,,,,,,,,,,,CLf,,,,,,,
,,,,,;LGGG,,,,:,,,,,,,,,,,,,,,,,,,LGCG,,,,,,
*******************************************/