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

Previous submission (verdict: Wrong answer on test 3):
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define mod 1000000007
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
double eps = 1e-12;
#define ln "\n"
#define printVector(a) for(int i=0; i<a.size(); i++){cout<<a[i]<<" ";}cout<<ln;
#define print_array(a,n) for(int i=0; i<n; i++){cout<<a[i]<<" ";}cout<<ln;
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define pb push_back
#define take_vector(a) for(auto &x:a)cin>>x;
#define take_array(a,n) for(int i=0;i<n;i++){cin>>a[i];}
#define take_matrix(a,m,n) for(int i=0; i<m; i++){for(int j=0; j<n; j++){cin>>a[i][j];}}
#define print_matrix(a,m,n) for(int i=0; i<m; i++){for(int j=0; j<n; j++){cout<<a[i][j]<<" ";}cout<<ln;}
#define fi first
#define se second
#define INF 2e18
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a/gcd(a,b))*b
#define count(a,x) count(a.begin(), a.end(),x)  
#define sum(a) accumulate(a.begin(), a.end(),0)
#define max_ele(a) *max_element(a.begin(), a.end())
#define min_ele(a) *min_element(a.begin(), a.end())

map<int,int> mp;

bool isPossible(int num){
 
    if( mp[num] ){

        mp[num]--;
        
        return 1;
    }

    if( num == 1 ) return false;

    return isPossible( num / 2 ) and isPossible( (num + 1)/2 );

}

int32_t main()
{
  fast_cin();

  int t;
  cin >> t;

  while (t--)
  {

    int n,m;
    cin>>n>>m;

    vector<int> a(n,0);
    for( int i = 0; i < n;  i++ ){ cin>>a[i]; mp[a[i]]++; }

    vector<int> b(m,0);
    for( int i = 0; i < m ; i++ ){ cin>>b[i]; }

    if( sum(a) != sum(b) ){ cout<<"NO"<<endl; continue; }

    sort(b.begin(),b.end());

    bool flag = 1;

    for( auto it : b ){
        if( !isPossible(it) ){
            flag = 0;
            break;
        }
    }

    if( flag == 1 ) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    

  }
  return 0;
}

Submission (verdict: Accepted):
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define mod 1000000007
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
double eps = 1e-12;
#define ln "\n"
#define printVector(a) for(int i=0; i<a.size(); i++){cout<<a[i]<<" ";}cout<<ln;
#define print_array(a,n) for(int i=0; i<n; i++){cout<<a[i]<<" ";}cout<<ln;
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define pb push_back
#define take_vector(a) for(auto &x:a)cin>>x;
#define take_array(a,n) for(int i=0;i<n;i++){cin>>a[i];}
#define take_matrix(a,m,n) for(int i=0; i<m; i++){for(int j=0; j<n; j++){cin>>a[i][j];}}
#define print_matrix(a,m,n) for(int i=0; i<m; i++){for(int j=0; j<n; j++){cout<<a[i][j]<<" ";}cout<<ln;}
#define fi first
#define se second
#define INF 2e18
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a/gcd(a,b))*b
#define count(a,x) count(a.begin(), a.end(),x)  
#define sum(a) accumulate(a.begin(), a.end(),0)
#define max_ele(a) *max_element(a.begin(), a.end())
#define min_ele(a) *min_element(a.begin(), a.end())

map<int,int> mp;

bool isPossible(int num){
 
    if( mp[num] ){

        mp[num]--;
        
        return 1;
    }

    if( num == 1 ) return false;

    return isPossible( num / 2 ) and isPossible( (num + 1)/2 );

}

int32_t main()
{
  fast_cin();

  int t;
  cin >> t;

  while (t--)
  {

    int n,m;
    cin>>n>>m;

    mp.clear();
    
    vector<int> a(n,0);
    for( int i = 0; i < n;  i++ ){ cin>>a[i]; mp[a[i]]++; }

    vector<int> b(m,0);
    for( int i = 0; i < m ; i++ ){ cin>>b[i]; }

    if( sum(a) != sum(b) ){ cout<<"NO"<<endl; continue; }

    sort(b.begin(),b.end());

    bool flag = 1;

    for( auto it : b ){
        if( !isPossible(it) ){
            flag = 0;
            break;
        }
    }

    if( flag == 1 ) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    

  }
  return 0;
}