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 gc getchar_unlocked
#define fo(i, a, b) for (auto i = (a); i < (b); ++i)
#define arrin(a, n) fo(i, 0, n) cin >> a[i] 
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define deb3(x, y, z) cout << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define pow2(n) static_cast<uint64_t>(1) << n;
typedef pair<int, int>    pii;
typedef pair<ll, ll>      pl;
typedef vector<int>       vi;
typedef vector<ll>        vl;
typedef vector<pii>       vpii;
typedef vector<pl>        vpl;
typedef vector<vi>        vvi;
typedef vector<vl>        vvl;
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
void yes() {cout << "YES" << endl;}
void no() {cout << "NO" << endl;}
void printvec(vl v){
     for(int i=0;i<v.size();i++){ cout<<v[i]<<" "; }
     cout<<endl;
}
ll lcm(ll a, ll b) {
    ll x = a/__gcd(a,b);
    return x*b;
}
ll ceil_d(ll dividend, ll divisor) {
    return (dividend+divisor-1)/divisor;
}
const int mod = 998244353;
long long power_mod(long long base, long long exponent) {
    long long res = 1;
    base %= mod;
    while (exponent > 0) {
        if (exponent & 1) {
            res = (res * base) % mod;
        }
        base = (base * base) % mod;
        exponent >>= 1;
    }
    return res;
}
const int MAXN = 2e5 + 5;
ll fact[MAXN];
ll nCr(ll n, ll k) {
	if(n < k) return 0LL;
	return (fact[n] * power_mod((fact[n - k] * fact[k]) % mod, mod - 2)) % mod;
}
void makefact() {
    fact[0] = 1;
	for(ll i = 1; i < MAXN; ++i) fact[i] = (fact[i - 1] * i) % mod;
}
ll seg[4 * MAXN]; ll arr[MAXN]; ll lazy[4 * MAXN]; 
void build_seg_tree(ll ind, ll low, ll high) {
    if(low==high) {
        seg[ind] = arr[low];
        return;
    }
    ll mid=low+(high-low)/2;
    build_seg_tree(2*ind+1, low, mid);
    build_seg_tree(2*ind+2, mid+1, high);
    // seg[ind]=max(seg[2*ind+1], seg[2*ind+2]); //for max
    // seg[ind]=min(seg[2*ind+1], seg[2*ind+2]); //for min
    seg[ind] = __gcd(seg[2 * ind + 1] , seg[2 * ind + 2]); //for sum
}
void build(ll n) {
    build_seg_tree(0,0,n-1);
}
void propagate(ll ind, ll low, ll high) {
    if (lazy[ind] != 0) {
        seg[ind] += (high - low + 1) * lazy[ind];
        if (low != high) {
            lazy[2 * ind + 1] += lazy[ind];
            lazy[2 * ind + 2] += lazy[ind];
        }
        lazy[ind] = 0; 
    }
}
ll query_seg_tree(ll ind, ll low, ll high, ll l, ll r) {
    if(low>=l && high<=r) return seg[ind];
    if(high<l || low>r) {
        // return INT_MIN; //for max
        // return 1e9; //for min
        return 0; //for sum
    }
    ll mid=low+(high-low)/2;
    ll left=query_seg_tree(2*ind+1, low, mid, l, r);
    ll right=query_seg_tree(2*ind+2, mid+1, high, l, r);
    // return max(left,right); //for max
    // return min(left,right); //for min
    return __gcd(left,right); //for sum
}
void range_update_seg_tree(ll ind, ll low, ll high, ll l, ll r, ll value) {
    propagate(ind, low, high); 
    if (low > r || high < l) return; 
    if (low >= l && high <= r) { 
        seg[ind] += (high - low + 1) * value;
        if (low != high) {
            lazy[2 * ind + 1] += value;
            lazy[2 * ind + 2] += value;
        }
        return;
    }
    ll mid = low + (high - low) / 2;
    range_update_seg_tree(2 * ind + 1, low, mid, l, r, value);
    range_update_seg_tree(2 * ind + 2, mid + 1, high, l, r, value);
    seg[ind] = seg[2 * ind + 1] + seg[2 * ind + 2];
}
ll point_query(ll ind, ll low, ll high, ll idx) {
    propagate(ind, low, high); 
    if (low == high) return seg[ind];
    ll mid = low + (high - low) / 2;
    if (idx <= mid) return point_query(2 * ind + 1, low, mid, idx);
    else return point_query(2 * ind + 2, mid + 1, high, idx);
}
ll get_value_at_id(ll idx, ll n) {
    return point_query(0, 0, n - 1, idx);
}
void update(ll l, ll r, ll value, ll n) {
    range_update_seg_tree(0, 0, n - 1, l, r, value);
}
ll query(ll l, ll r, ll n) {
    return query_seg_tree(0,0,n-1,l,r);
}
struct pair_hash {
    template <typename T1, typename T2>
    size_t operator()(const pair<T1, T2>& p) const {
        auto h1 = hash<T1>{}(p.first);
        auto h2 = hash<T2>{}(p.second);
        return h1 ^ (h2 << 1);
    }
};
struct DSU{
    vi rank,par,size;
    int max_size;
    DSU(int n) {
        rank.resize(n+1,0);
        par.resize(n+1);
        size.resize(n+1);
        max_size = 1;
        for(int i=0; i<=n; i++) {
            par[i] = i; size[i] = 1;
        }
    }
    int findPar(int u) {
        if(par[u]==u) return u;
        return par[u] = findPar(par[u]);
    }
    void union_size(int u, int v) {
        int pu = findPar(u); int pv = findPar(v);
        if(pu==pv) return;
        if(size[pu]<size[pv]) {
            par[pu] = pv;
            size[pv]+=size[pu];
            max_size = max(max_size, size[pv]);
        }
        else {
            par[pv] = pu;
            size[pu]+=size[pv];
            max_size = max(max_size, size[pu]);
        }
    }
    void union_rank(int u, int v) {
        int pu = findPar(u); int pv = findPar(v);
        if(pu==pv) return;
        if(rank[pu]<rank[pv]) {
            par[pu] = pv;
        }
        else if(rank[pv]<rank[pu]) {
            par[pv] = pu;
        }
        else {
            par[pv] = pu;
            rank[pu]++;
        }
    }
    bool same_comp(int u, int v) {
        return findPar(u)==findPar(v);
    }
    int getMaxSize() {
        return max_size;
    }
};
// =========================================================================== //
/*
      *       ******    *****    *    *    *       *          *       *   *
     * *      *    *    *    *   *    *    *       *         * *      *   *
    *****     ******    *    *   *    *    *       *        *****     *****
   *     *    *    *    *    *   *    *    *       *       *     *    *   *
  *       *   ******    *****     ****     *****   *****  *       *   *   *
 
*/

void solve() {
    int n,m;
    cin >> n >> m;
    vl a(n);
    vl b(m);
    arrin(a,n); arrin(b,m);
    sort(all(a));
    sort(all(b));
    if(a.size()==b.size()) {
        if(a==b) yes();
        else no();
        return;
    }
    priority_queue<ll, vl, greater<ll>> pq;
    fo(i,0,m) pq.push(b[i]);
    unordered_map<ll, int> abd;
    fo(i,0,n) abd[a[i]]++;
    while(!pq.empty()) {
        if(pq.top()==1 && abd[1]==0) break;
        ll el=pq.top();
        if(abd[el]>0) {
            abd[el]--; pq.pop();
        }
        else {
            ll x=el/2; ll y=ceil_d(el,2);
            pq.pop();
            pq.push(x); pq.push(y);
        }
    }
    bool ans=true;
    tr(it,abd) {
        if(it->S>0) {
            ans=false; break;
        }
    }
    if(ans) yes();
    else no();

     

}


int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());
    int tc = 1;
    cin >> tc;
    while (tc--) {
        solve();
    }
    return 0;
}

Submission (verdict: Accepted):

#include<bits/stdc++.h>
using namespace std;
#define int long long
int32_t main(){

#ifdef ONLINEJUDGE
   freopen("input.txt","r",stdin);
   freopen("output.txt","w",stdout);
#endif

int t = 1;
cin>>t;
while(t--){
	int n,m,p1,q1,p2;
	bool bb=0;
	cin>>n>>m;
	 // cout<<n<<" "<<m<<"\n";
	int i,j;
	vector<int> a(n),b(m);
	priority_queue<int,vector<int>,greater<int>> p,q;
	for(i=0;i<n;i++){
		cin>>a[i];	
		p.push(a[i]);
	}
	for(j=0;j<m;j++){
		cin>>b[j];
		q.push(b[j]);
	}
	while(1){
		if(p.empty()||q.empty())break;
		p1 = p.top();
		q1 = q.top();
		if(p.size()==1){
			if(q.size()!=1)break;
			
			if(p1==q1)bb=1;
			break;
		}
		if(p1==q1){
			p.pop();
			q.pop();
		}else if(p1>q1){
			break;
		}else{
			p.pop();
			p2 = p.top();
			p.pop();
			if(p2-p1<=1){
				p.push(p1+p2);
			}
			else break;
		}
	}
	// while(!p.empty()){
	// 	cout<<p.top()<<" ";
	// 	p.pop();
	// }cout<<"\n";
	// while(!q.empty()){
	// 	cout<<q.top()<<" ";
	// 	q.pop();
	// }
	if(p.empty()&&q.empty())bb=1;
	if(bb)cout<<"YES\n";
	else cout<<"NO\n";
}

return 0;
}