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

Previous submission (verdict: Wrong answer on test 3):
#include <bits/stdc++.h>
using namespace std;
#define int long long
int mod = 998244353;
#define fr(i, n) for (int i = 0; i < n; i++)
#define fr1(i, n) for (int i = 1; i < n; i++)
#define vi vector<int>
int hcf(int a, int g)
{
    if (g == 0)
        return a;
    else
        return hcf(g, a % g);
}
int lcm(int a, int g) { return (a * g) / hcf(a, g); }
int modInverse(int a, int mod) {
    int res = 1, p = mod - 2;
    while (p > 0) {
        if (p & 1) res = (res * a) % mod;
        a = (a * a) % mod;
        p >>= 1;
    }
    return res;
}
int N=1e6;
vi f(N+1,1),inv_f(N+1,1);
void precompute() {
    for (int i = 2; i <= N; ++i) {
        f[i] = (f[i - 1] * i) % mod;
    }
    inv_f[N] = modInverse(f[N], mod);
    for (int i = N - 1; i >= 1; --i) {
        inv_f[i] = (inv_f[i + 1] * (i + 1)) % mod;
    }
}
int ncr(int n, int r) {
    if (r > n) return 0;
    return (f[n] * inv_f[r] % mod) * inv_f[n - r] % mod;
}

void solve()
{
    int n,m;
    cin>>n>>m;
    vi a(n);
    vi b(m);
    fr(i,n) cin>>a[i];
    fr(i,m) cin>>b[i];
    map<int,int> ma,mb;
    fr(i,m){
        mb[b[i]]++;
    }
    fr(i,n){
        ma[a[i]]++;
    }
    sort(a.begin(),a.end());
    fr(i,n){
        if(ma[a[i]]>=mb[a[i]]){
            ma[a[i]]-=mb[a[i]];
            mb[a[i]]=0;
        }
    }
    int f=0,x=0;

    for(int i=0;i<n;i++){
        if(ma[a[i]]==0) continue;
        else{
            if(f==0){
                x=a[i];
                ma[x]--;
                f=1;
            }
            else if(a[i]-x<=1){
                if(mb[x+a[i]]>0){ 
                mb[x+a[i]]--;
                f=0;
                x=0;
                }
                else x=x+a[i];
                ma[a[i]]--;
            }
        
        }
    }
    if(x!=0){
        cout<<"NO"<<endl;
        return;
    }
    fr(i,m){
        if(mb[b[i]]==0 && ma[b[i]]==0) continue;
        else{
            cout<<"NO"<<endl;
            return;
        }
    }
    cout<<"YES"<<endl;
   

}
signed main()
{
    int t;
    cin>>t;
    while(t--)
    solve();
    return 0;
}


Submission (verdict: Wrong answer on test 3):
#include <bits/stdc++.h>
using namespace std;
#define int long long
int mod = 998244353;
#define fr(i, n) for (int i = 0; i < n; i++)
#define fr1(i, n) for (int i = 1; i < n; i++)
#define vi vector<int>
int hcf(int a, int g)
{
    if (g == 0)
        return a;
    else
        return hcf(g, a % g);
}
int lcm(int a, int g) { return (a * g) / hcf(a, g); }
int modInverse(int a, int mod) {
    int res = 1, p = mod - 2;
    while (p > 0) {
        if (p & 1) res = (res * a) % mod;
        a = (a * a) % mod;
        p >>= 1;
    }
    return res;
}
int N=1e6;
vi f(N+1,1),inv_f(N+1,1);
void precompute() {
    for (int i = 2; i <= N; ++i) {
        f[i] = (f[i - 1] * i) % mod;
    }
    inv_f[N] = modInverse(f[N], mod);
    for (int i = N - 1; i >= 1; --i) {
        inv_f[i] = (inv_f[i + 1] * (i + 1)) % mod;
    }
}
int ncr(int n, int r) {
    if (r > n) return 0;
    return (f[n] * inv_f[r] % mod) * inv_f[n - r] % mod;
}

void solve()
{
    int n,m;
    cin>>n>>m;
    vi a(n);
    vi b(m);
    fr(i,n) cin>>a[i];
    fr(i,m) cin>>b[i];
    map<int,int> ma,mb;
    fr(i,m){
        mb[b[i]]++;
    }
    fr(i,n){
        ma[a[i]]++;
    }
    sort(a.begin(),a.end());
    fr(i,m){
        if(ma[b[i]]>0 && mb[b[i]]>0){
            int y=min(ma[b[i]],mb[b[i]]);
            ma[b[i]]-=y;
            mb[b[i]]-=y;
        }
    }
    int f=0,x=0;

    for(int i=0;i<n;i++){
        if(ma[a[i]]==0) continue;
        else{
            if(f==0){
                x=a[i];
                ma[x]--;
                f=1;
            }
            else if(a[i]-x<=1){
                if(mb[x+a[i]]>0){ 
                mb[x+a[i]]--;
                f=0;
                x=0;
                }
                else x=x+a[i];
                ma[a[i]]--;
            }
        
        }
    }
    if(x!=0){
        cout<<"NO"<<endl;
        return;
    }
    fr(i,m){
        if(mb[b[i]]==0 && ma[b[i]]==0) continue;
        else{
            cout<<"NO"<<endl;
            return;
        }
    }
    cout<<"YES"<<endl;
   

}
signed main()
{
    int t;
    cin>>t;
    while(t--)
    solve();
    return 0;
}