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 inf numeric_limits<int>::max()
#define rinf numeric_limits<int>::min()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define ll long long
#define rep(i, s, e) for(int i=s; i<e; i++)
#define rrep(i, s, e) for(int i=e-1; i>=s; i--)
#define pb push_back
#define endl "\n";
#define yes cout << "YES" << endl
#define no cout << "NO" << endl

void solve() {
    ll n, m; 
    cin >> n >> m;
    multiset<ll> a, b;
    rep(i, 0, n) {
        ll in;
        cin >> in;
        a.insert(in);
    }
    rep(i, 0, m) {
        ll in;
        cin >> in;
        b.insert(in);
    }
    while(a.size() && b.size()){
        ll x = *a.begin(), y = *b.begin();
        if(x == y) {
            a.erase(a.begin());
            b.erase(b.begin());
        } else {
            auto it1 = a.begin();
            it1++;
           if(it1 == a.end() || (*it1 - x) > 1) {
            no;
            return;
           } else {
            ll x2 = *it1;
            a.erase(a.begin());
            a.erase(a.begin());
            a.insert(x + x2);
           }
        }
    }
    if(a.size() || b.size()) {
        no;
    } else {
        yes;
    }

}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //cout << fixed << setprecision(12);
    
    // freopen("f.in", "r", stdin);
	// freopen("f.out", "w", stdout);
    
    ll t = 1; 
    cin >> t;
    while(t--) solve();
}

Submission (verdict: Time limit exceeded on test 1):
#include <bits/stdc++.h>
using namespace std;
#define inf numeric_limits<int>::max()
#define rinf numeric_limits<int>::min()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define ll long long
#define rep(i, s, e) for(int i=s; i<e; i++)
#define rrep(i, s, e) for(int i=e-1; i>=s; i--)
#define pb push_back
#define endl "\n";
#define yes cout << "YES" << endl
#define no cout << "NO" << endl

void solve() {
    ll n, m; 
    cin >> n >> m ;
    multiset<ll, greater<ll>> a,b;
    rep(i,0,n) {
        ll in ; cin >> in;
        a.insert(in);
    }
    rep(i,0,m) {
        ll in ; cin >> in;
        auto it = a.find(in);
        if(it != a.end()) {
            a.erase(it);
        } else {
            b.insert(in);
        }
    }

    while(a.size() && b.size()) {
        // cout << "herr" << endl;
        if(*a.begin() == *b.begin()) {
            a.erase(a.begin());
            b.erase(b.begin());
        } else if(*a.begin() < *b.begin()) {
            ll y1 = floor((float)*b.begin() / 2);
            ll y2 = ceil((float)*b.begin() / 2);
            // cout << y1 << " " << y2 << endl;
            b.erase(b.begin());
            b.insert(y1);
            b.insert(y2);
        } else {
            break;
        }
    }
    if(a.size() || b.size()) {
        no;
    } else {
        yes;
    }
    
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //cout << fixed << setprecision(12);
    
    // freopen("f.in", "r", stdin);
	// freopen("f.out", "w", stdout);
    
    ll t = 1; 
    cin >> t;
    while(t--) solve();
}