Problem: 2061D - Kevin and Numbers
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 3):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define min(a, b) (a < b ? a : b)
#define max(a, b) (a > b ? a : b)
#define PB push_back
#define UM unordered_map
#define sf1(a) scanf("%lld", &a) 
#define sf2(a,b) scanf("%lld %lld", &a, &b)
#define pf1(a) printf("%lld", a)
#define pf2(a,b) printf("%lld %lld", a, b)
#define enl "\n"
#define int long long
#define all(v) v.begin(),v.end()
#define vi vector<int>
#define mp std::make_pair

ll mod_factor = (ll)(1e9 + 7);

void input(vector<int>& v){
    for(int i = 0 ; i < v.size(); i++){
        cin >> v[i];
    }
}

bool isprime(ll n)
{
    ll b = 0;
    for (ll i = 2; i * i <= n; i++)
    {
        if (n % i == 0)
        {
            b++;
            break;
        }
    }
    if (b)
        return false;
    else
        return true;
}
 
bool is_palindrome(string v)
{
    FOR(i, 0, v.size() / 2)
    {
        if (v[i] != v[v.size() - 1 - i])
            return 0;
    }
    return 1;
}
 
bool isSubstring(string &a, string &b)
{
    return a.find(b) != string::npos;
}
 

 
bool isPerfectSquare(ll x)
{
    if (x >=0 ) {
        long long sr = sqrt(x);
        return (sr * sr == x);
    }
    return false;
}


 
ll gcd(ll a, ll b)
{
    if (a == 0)
        return b;
    return gcd(b % a, a);
}
 
void getPrimeFactors(ll n, unordered_map<ll,ll>&m) 
{ 
    while (n % 2 == 0) 
    { 
        m[2] += 1;
        n = n/2; 
    } 
    for (int i = 3; i <= sqrt(n); i = i + 2) 
    { 
        while (n % i == 0) 
        { 
            m[i] += 1; 
            n = n/i; 
        } 
    } 
    if (n > 2) 
        m[n] += 1; 
} 
 
 
vector<ll> makePrefix(vector<ll>& v){
        vector<int> prefix(v.size());
        prefix[0] = v[0];
        for(int i = 1; i < v.size(); i++){
            prefix[i] = prefix[i-1] + v[i];
        }




        // vector<ll> prefix(v.size()+1,0);
        // prefix[1] = v[0];
 
        // FOR(i,1,v.size()){
        //     prefix[i+1] = prefix[i] + v[i];
        // }
        return prefix;
}

 
template <typename T>
void vecprint(const vector<T>& v) {
    for (const auto& i : v) {
        cout << i << " ";
    }
    cout << endl;
}
unsigned long long binpow(unsigned long long a,unsigned long long b) {
    if (b == 0)
        return 1;
    unsigned long long res = binpow(a, b / 2)%mod_factor;
    if (b % 2)
        return (res * res * a)%mod_factor;
    else
        return (res * res)%mod_factor;
}
 
// *****************************

void solve() {
    int n,m;
    cin >> n >> m;
    vector<int> a(n);
    vector<int> b(m);
    input(a);
    input(b);

    priority_queue<int> q1;
    priority_queue<int> q2;
    for(auto &i : a){
        q1.push(-i);
    }
    for(auto &i : b){
        q2.push(-i);
    }

    while(!q1.empty() && !q2.empty()){
        int x1 = -q1.top();
        q1.pop();
        int y1 = -q2.top();
        q2.pop();
        if(x1 == y1){
            continue;
        }
        if(q1.empty() || x1 > y1){
            cout << "NO" << enl;
            return;
        }
        int x2 = -q1.top();
        q1.pop();
        if(x2 -x1 > 1){
            cout << "NO" << enl;
            return;
        }
        q1.push(-x1-x2);
        q2.push(-y1);
    }
    if(q1.size() || q2.size()){
        cout << "NO" << enl;
        return;
    }
    cout << "YES" << enl;
}   






signed main()
{

    ios_base::sync_with_stdio(0);
	cin.tie(0);

    ll t ;
    // t = 1;
    cin >> t;
    while(t--){
        solve();
    }
}

Submission (verdict: Wrong answer on test 3):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define min(a, b) (a < b ? a : b)
#define max(a, b) (a > b ? a : b)
#define PB push_back
#define UM unordered_map
#define sf1(a) scanf("%lld", &a) 
#define sf2(a,b) scanf("%lld %lld", &a, &b)
#define pf1(a) printf("%lld", a)
#define pf2(a,b) printf("%lld %lld", a, b)
#define enl "\n"
#define int long long
#define all(v) v.begin(),v.end()
#define vi vector<int>
#define mp std::make_pair
#define no cout << "NO" << enl;
#define yes cout << "YES" << enl;

ll mod_factor = (ll)(1e9 + 7);

void input(vector<int>& v){
    for(int i = 0 ; i < v.size(); i++){
        cin >> v[i];
    }
}

bool isprime(ll n)
{
    ll b = 0;
    for (ll i = 2; i * i <= n; i++)
    {
        if (n % i == 0)
        {
            b++;
            break;
        }
    }
    if (b)
        return false;
    else
        return true;
}
 
bool is_palindrome(string v)
{
    FOR(i, 0, v.size() / 2)
    {
        if (v[i] != v[v.size() - 1 - i])
            return 0;
    }
    return 1;
}
 
bool isSubstring(string &a, string &b)
{
    return a.find(b) != string::npos;
}
 

 
bool isPerfectSquare(ll x)
{
    if (x >=0 ) {
        long long sr = sqrt(x);
        return (sr * sr == x);
    }
    return false;
}


 
ll gcd(ll a, ll b)
{
    if (a == 0)
        return b;
    return gcd(b % a, a);
}
 
void getPrimeFactors(ll n, unordered_map<ll,ll>&m) 
{ 
    while (n % 2 == 0) 
    { 
        m[2] += 1;
        n = n/2; 
    } 
    for (int i = 3; i <= sqrt(n); i = i + 2) 
    { 
        while (n % i == 0) 
        { 
            m[i] += 1; 
            n = n/i; 
        } 
    } 
    if (n > 2) 
        m[n] += 1; 
} 
 
 
vector<ll> makePrefix(vector<ll>& v){
        vector<int> prefix(v.size());
        prefix[0] = v[0];
        for(int i = 1; i < v.size(); i++){
            prefix[i] = prefix[i-1] + v[i];
        }




        // vector<ll> prefix(v.size()+1,0);
        // prefix[1] = v[0];
 
        // FOR(i,1,v.size()){
        //     prefix[i+1] = prefix[i] + v[i];
        // }
        return prefix;
}

 
template <typename T>
void vecprint(const vector<T>& v) {
    for (const auto& i : v) {
        cout << i << " ";
    }
    cout << endl;
}
unsigned long long binpow(unsigned long long a,unsigned long long b) {
    if (b == 0)
        return 1;
    unsigned long long res = binpow(a, b / 2)%mod_factor;
    if (b % 2)
        return (res * res * a)%mod_factor;
    else
        return (res * res)%mod_factor;
}
 
// *****************************

void solve() {
    int n,m;
    cin >> n >> m;
    vector<int> a(n);
    vector<int> b(m);
    input(a);
    input(b);

    priority_queue<int> q1;
    priority_queue<int> q2;
    for(auto &i : a){
        q1.push(-i);
    }
    for(auto &i : b){
        q2.push(-i);
    }

    while(!q1.empty() && !q2.empty()){
        int x1 = -q1.top();
        q1.pop();
        int y1 = -q2.top();
        q2.pop();
        if(x1 == y1){
            continue;
        }
        if(q1.empty()){
            no;
            return;
        }
        int x2 = -q1.top();
        q1.pop();
        if(x2 - x1 > 1){
            no;
            return;
        }
        q1.push(-x2 - x1);
        q2.push(-y1);
    }
    if(!q1.empty() || !q2.empty()){
        no;
        return;
    }
    yes;
  
}   






signed main()
{

    ios_base::sync_with_stdio(0);
	cin.tie(0);

    ll t ;
    // t = 1;
    cin >> t;
    while(t--){
        solve();
    }
}