Problem: 2061D - Kevin and Numbers
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 2):
#include <iostream>
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
const ll mod = 1e9 + 7;
const ll modd = 998244353;


void solve() {
    ll n, m;
    cin>>n>>m;
    map<ll, ll>m1, m2;
    for(ll i = 0; i<n; i++) {
        ll x;
        cin>>x;
        m1[x]++;
    }
    for(ll i = 0; i<m; i++) {
        ll x;
        cin>>x;
        m2[x]++;
    }

    set<ll>s1, s2;
    for(auto&i:m1) {
        if(m2.find(i.first)!=m2.end()){
            ll k = m2[i.first];
            if(k>i.second) {
                m2[i.first]-=i.second;
                s1.insert(i.first);
            }
            else {
                i.second-=k;
                s2.insert(i.first);
                if(i.second == 0) s1.insert(i.first);
            }
        }
    }
    for(auto&i:s1) {
        m1.erase(i);
    }
    for(auto&i:s2) {
        m2.erase(i);
    }
    vector<ll>a, b;
    for(auto&i:m1) {
        ll k = i.second;
       //  cout<<i.first<<" "<<k<<"\n";
        while(k--) {
            a.push_back(i.first);
           //  cout<<i.first<<" ";
        }
    }
  //  cout<<"\n";

    for(auto&i:m2) {
        ll k = i.second;
       // cout<<i.first<<" "<<k<<"\n";
        while(k--) {
            b.push_back(i.first);
           // <F5> cout<<i.first<<" ";
        }
    }
   //  cout<<"\n";
    n = a.size(), m = b.size();
    if(n<m) {
        cout<<"NO\n";
        return;
    }

    ll i = 0, j = 0;

    while(i<n && j<m) {
        if(a[i]==b[j]) {
            i++;
            j++;
        }
        else if(b[j]<a[i]) {
            cout<<"NO\n";
            return;
        }
        else {
            ll prev = -1, s = 0;
            while(i<n && (prev == -1 ||abs(a[i]-prev<=1)) ){
                s+=a[i];
                prev = s;
                i++;
                if(b[j]==s) {
                    j++;
                    break;
                }
                else if(s>b[j]) {
                    cout<<"NO\n";
                    return;
                }
            }
  
        }
    }
    if(i<n ||  j<m) {
        cout<<"NO\n";
        return;
    }
    cout<<"YES\n";


}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int t = 1;
    cin >> t;
    
    while (t--) solve();

    return 0;
}


Submission (verdict: Wrong answer on test 3):
#include <iostream>
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
const ll mod = 1e9 + 7;
const ll modd = 998244353;


void solve() {
    ll n, m;
    cin>>n>>m;
    map<ll, ll>m1, m2;
    for(ll i = 0; i<n; i++) {
        ll x;
        cin>>x;
        m1[x]++;
    }
    for(ll i = 0; i<m; i++) {
        ll x;
        cin>>x;
        m2[x]++;
    }

    set<ll>s1, s2;
    for(auto&i:m1) {
        if(m2.find(i.first)!=m2.end()){
            ll k = m2[i.first];
            if(k>i.second) {
                m2[i.first]-=i.second;
                s1.insert(i.first);
            }
            else {
                i.second-=k;
                s2.insert(i.first);
                if(i.second == 0) s1.insert(i.first);
            }
        }
    }
    for(auto&i:s1) {
        m1.erase(i);
    }
    for(auto&i:s2) {
        m2.erase(i);
    }
    vector<ll>a, b;
    for(auto&i:m1) {
        ll k = i.second;
       //  cout<<i.first<<" "<<k<<"\n";
        while(k--) {
            a.push_back(i.first);
           //  cout<<i.first<<" ";
        }
    }
  //  cout<<"\n";

    for(auto&i:m2) {
        ll k = i.second;
       // cout<<i.first<<" "<<k<<"\n";
        while(k--) {
            b.push_back(i.first);
           // <F5> cout<<i.first<<" ";
        }
    }
   //  cout<<"\n";
    n = a.size(), m = b.size();
    if(n<m) {
        cout<<"NO\n";
        return;
    }

    ll i = 0, j = 0;

    while(i<n && j<m) {
        if(a[i]==b[j]) {
            i++;
            j++;
        }
        else if(b[j]<a[i]) {
            cout<<"NO\n";
            return;
        }
        else {
            ll prev = -1, s = 0;
            while(i<n && (prev == -1 ||abs(a[i]-prev)<=1) ){
                s+=a[i];
                prev = s;
                i++;
                if(b[j]==s) {
                    j++;
                    break;
                }
                else if(s>b[j]) {
                    cout<<"NO\n";
                    return;
                }
            }
            if(b[j-1]!=s) {
                cout<<"NO\n";
                return;
            }
  
        }
    }
    if(i<n ||  j<m) {
        cout<<"NO\n";
        return;
    }
    cout<<"YES\n";


}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int t = 1;
    cin >> t;
    
    while (t--) solve();

    return 0;
}