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;
typedef long long int ll;
#define fast() ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
int main(){
fast();
int t;
cin>>t;
while(t--){
ll n,m;
cin>>n>>m;
vector<ll> a,b;
for(ll i=0;i<n;i++){
    ll x;
    cin>>x;
    a.push_back(x);
}
for(ll i=0;i<m;i++){
    ll x;
    cin>>x;
    b.push_back(x);
}
sort(a.begin(),a.end());
sort(b.begin(),b.end());
if(b==a){
    cout<<"Yes"<<endl;
    continue;
}
if(b.size()>=a.size()){
    cout<<"No"<<endl;
    continue;
}
ll fg=0;
map<ll,ll> aa,bb;
for(ll i=0;i<n;i++){
  aa[a[i]]++;
}
for(ll i=0;i<m;i++){
    bb[b[i]]++;
}
for(auto &e : bb){
    if(aa[e.first]>0){
        aa[e.first]-=min(aa[e.first],bb[e.first]);
        bb[e.first]-=min(aa[e.first],bb[e.first]);
    }
}
a.clear(),b.clear();
for(auto &e : aa){
    while(e.second!=0){
        a.push_back(e.first);
        e.second--;
    }
}
for(auto &e : bb){
    while(e.second!=0){
        b.push_back(e.first);
        e.second--;
    }
}
// for(auto & e : a){
//     cout<<e<<" ";
// }
// cout<<endl;
// for(auto & e : b){
//     cout<<e<<" ";
// }
// cout<<endl;
m=b.size();
n=a.size();
for(ll i=0;i<m;i++){
    if(i+1==a.size()){
        fg=1;
        break;
    }
    if(a[i]!=b[i]){
        if(abs(a[i]-a[i+1])>=2){
            fg=1;
            break;
        }else{
            a[i]+=a[i+1];
            a.erase(find(a.begin(),a.end(),a[i+1]));
            i--;
        }
    }
}
if(a==b){
    cout<<"Yes"<<endl;
    continue;
}
if(fg || a.size()!=m){
    cout<<"No"<<endl;
}else{
    cout<<"Yes"<<endl;
}





}
return 0;
}


Submission (verdict: Wrong answer on test 3):
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define fast() ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
int main(){
fast();
int t;
cin>>t;
while(t--){
ll n,m;
cin>>n>>m;
vector<ll> a,b;
for(ll i=0;i<n;i++){
    ll x;
    cin>>x;
    a.push_back(x);
}
for(ll i=0;i<m;i++){
    ll x;
    cin>>x;
    b.push_back(x);
}
sort(a.begin(),a.end());
sort(b.begin(),b.end());
if(b==a){
    cout<<"Yes"<<endl;
    continue;
}
if(b.size()>=a.size()){
    cout<<"No"<<endl;
    continue;
}
ll fg=0;
map<ll,ll> aa,bb;
for(ll i=0;i<n;i++){
  aa[a[i]]++;
}
for(ll i=0;i<m;i++){
    bb[b[i]]++;
}
for(auto &e : bb){
    if(aa[e.first]>0){
        int pk = aa[e.first],kp=bb[e.first];
        aa[e.first]-=min(kp,pk);
        bb[e.first]-=min(kp,pk);
    }
}
a.clear(),b.clear();
for(auto &e : aa){
    while(e.second!=0){
        a.push_back(e.first);
        e.second--;
    }
}
for(auto &e : bb){
    while(e.second!=0){
        b.push_back(e.first);
        e.second--;
    }
}
// for(auto & e : a){
//     cout<<e<<" ";
// }
// cout<<endl;
// for(auto & e : b){
//     cout<<e<<" ";
// }
//cout<<endl;
m=b.size();
n=a.size();
for(ll i=0;i<m;i++){
    if(i+1==a.size()){
        fg=1;
        break;
    }
    if(a[i]!=b[i]){
        if(abs(a[i]-a[i+1])>=2){
            fg=1;
            break;
        }else{
            a[i]+=a[i+1];
            a.erase(find(a.begin(),a.end(),a[i+1]));
            i--;
        }
    }
}
if(a==b){
    cout<<"Yes"<<endl;
    continue;
}
if(fg || a.size()!=m){
    cout<<"No"<<endl;
}else{
    cout<<"Yes"<<endl;
}





}
return 0;
}