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

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

const int N=2e5+50;
int a[N],b[N];

signed main(){
    int t;
    cin>>t;
    while(t--){
        int n,m;
        cin>>n>>m;
        map<int,int> p2;
        int sum1=0,sum2=0;
        for(int i=0;i<n;i++){
            cin>>a[i];
            sum1+=a[i];
        }
        for(int j=0;j<m;j++){
            cin>>b[j];
            p2[b[j]]++;
            sum2+=b[j];
        }
        if(sum1!=sum2){
            cout<<"No"<<endl;
            continue;
        }
        vector<int> v;
        sort(a,a+n);
        for(int i=0;i<n;i++){
            if(p2[a[i]]>=1){
                p2[a[i]]--;
            }else{
                
                if(!v.empty()){
                    if(p2[v.back()]>=1){
                        p2[v.back()]--;
                        v.pop_back();
                    }
                    if(!v.empty()&&abs(v.back()-a[i])<=1){
                        int u=v.back();
                        v.pop_back();
                        v.push_back(a[i]+u);
                     //   cout<<v.back()<<endl;
                    }
                    if(!v.empty()&&p2[v.back()]>=1){
                        p2[v.back()]--;
                        v.pop_back();
                    }
                }else{
                    v.push_back(a[i]);
                }
            }
        }
        int flag=0;
        for(auto i:p2){
            if(i.second>0){
                flag=1;
                break;
            }
        }    
        if(!v.empty()||flag){
            cout<<"No"<<endl;
        }else{
            cout<<"Yes"<<endl;
        }
    }
    return 0;
}
// 1中和相等
// 2 最大 小于 下面
// 3如果长度相等 判断 是否一样
// 4

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

const int N=2e5+50;
int a[N],b[N];

signed main(){
    int t;
    cin>>t;
    while(t--){
        int n,m;
        cin>>n>>m;
        map<int,int> p2;
        int sum1=0,sum2=0;
        for(int i=0;i<n;i++){
            cin>>a[i];
            sum1+=a[i];
        }
        for(int j=0;j<m;j++){
            cin>>b[j];
            p2[b[j]]++;
            sum2+=b[j];
        }
        if(sum1!=sum2){
            cout<<"No"<<endl;
            continue;
        }
        vector<int> v;
        sort(a,a+n);
        for(int i=0;i<n;i++){
            if(p2[a[i]]>=1){
                p2[a[i]]--;
            }else{
                
                if(!v.empty()){
                    if(p2[v.back()]>=1){
                        p2[v.back()]--;
                        v.pop_back();
                    }
                    if(!v.empty()&&abs(v.back()-a[i])<=1){
                        int u=v.back();
                        v.pop_back();
                        v.push_back(a[i]+u);
                     //   cout<<v.back()<<endl;
                    }else{
                        v.push_back(a[i]);
                    }
                    if(!v.empty()&&p2[v.back()]>=1){
                        p2[v.back()]--;
                        v.pop_back();
                    }
                }else{
                    v.push_back(a[i]);
                }
            }
        }
        int flag=0;
        for(auto i:p2){
            if(i.second>0){
                flag=1;
                break;
            }
        }    
        if(!v.empty()||flag){
            cout<<"No"<<endl;
        }else{
            cout<<"Yes"<<endl;
        }
    }
    return 0;
}
// 1中和相等
// 2 最大 小于 下面
// 3如果长度相等 判断 是否一样
// 4