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

Previous submission (verdict: Time limit exceeded on test 6):
#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())

int32_t main()
{
  fast_cin();

  int t;
  cin >> t;

  while (t--)
  {

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

    map<int,int> mp1;
    map<int,int,greater<int>> mp2;

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

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

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

    while( mp1.size() and mp2.size() ){

        auto it = mp2.begin();

        int num = it->first;

        // dbg(num);

        int f1 = it->second;
       
        if( mp1.find(num) != mp1.end() ){
            int f2 = mp1[num];

            int toDel = min(f1,f2);

            mp2[num] -= toDel;
            mp1[num] -= toDel;

            if( mp2[num] == 0 ) mp2.erase(num);
            if( mp1[num] == 0 ) mp1.erase(num);    

        }
        else{

            if( num == 1 ) break;

            int x = num/2;
            int y = (num+1)/2;
            mp2[x]++; mp2[y]++;

            mp2[num]--;

            if( mp2[num] == 0 ) mp2.erase(num);

            
        }

    }

    if( mp1.empty() and mp2.empty() ) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    

  }
  return 0;
}

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;
}