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;

typedef long long ll;
typedef pair<ll,ll> pll;
const ll N = 2e5+10;
vector <ll> e[N];

void solve() {
    ll n,m; cin>>n>>m;
    multiset <ll> st1,st2;
    for(ll i=1;i<=n;i++) {
        ll x; cin>>x;
        st1.insert(x);
    }
    for(ll i=1;i<=m;i++) {
        ll x; cin>>x;
        st2.insert(x);
    }
    while (st1.size() > st2.size()) {
        ll x1 = *(st1.begin()),x2 = *(st2.begin());
        if(x1 == x2) {
            st1.erase(st1.begin());
            st2.erase(st2.begin());
        } else if(x1 > x2) {
            cout<<"No"<<endl;
            return;
        } else {
            st1.erase(st1.begin());
            ll x3 = *(st1.begin());
            st1.erase(st1.begin());
            if(x3 - x1 > 1) {
                cout<<"No"<<endl;
                return;
            }
            st1.insert(x1+x3);
        }
    }
    auto it1 = st1.begin(),it2 = st2.begin();
    while (it1 != st1.end() && it2 != st2.end()) {
        if(*it1 != *it2) {
            cout<<"No"<<endl;
            return;
        } 
        // cout<<*it1<<' '<<*it2<<endl;
        it1++;
        it2++;
    }
    cout<<"Yes"<<endl;
}

int main() {
ios::sync_with_stdio(0);
std::cin.tie(0);
std::cout.tie(0);
ll t =1;
cin>>t;
while(t--) solve();
return 0;
}

Submission (verdict: Time limit exceeded on test 3):
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<ll,ll> pll;
const ll N = 2e5+10;
vector <ll> e[N];

void solve() {
    ll n,m; cin>>n>>m;
    multiset <ll> st1,st2;
    for(ll i=1;i<=n;i++) {
        ll x; cin>>x;
        st1.insert(x);
    }
    for(ll i=1;i<=m;i++) {
        ll x; cin>>x;
        st2.insert(x);
    }
    while (st1.size() > st2.size()) {
        ll x1 = *(st1.begin()),x2 = *(st2.begin());
        if(x1 == x2) {
            st1.erase(st1.begin());
            st2.erase(st2.begin());
        } else if(x1 > x2) {
            cout<<"No"<<endl;
            return;
        } else {
            while(x1 < x2/2) {
                st1.erase(st1.begin());
                ll x3 = *(st1.begin());
                if(x3 - x1 > 1) {
                    cout<<"No"<<endl;
                    return;
                }
                st1.erase(st1.begin());
                st1.insert(x1+x3);
                x1 = *(st1.begin());
            }
            if(st1.find(x2) != st1.end()) {
                st1.erase(st1.find(x2));
                st2.erase(st2.begin());
                continue;
            }
            if(st1.find(x2-x1) != st1.end()) {
                st1.erase(st1.find(x2-x1));
                if(st1.find(x1) != st1.end()) {
                    st1.erase(st1.find(x1));
                    st2.erase(st2.begin());
                } else {
                    cout<<"No"<<endl;
                    return;
                }
            } else {
                cout<<"No"<<endl;
                return;
            }
        }
    }
    auto it1 = st1.begin(),it2 = st2.begin();
    while (it1 != st1.end() && it2 != st2.end()) {
        if(*it1 != *it2) {
            cout<<"No"<<endl;
            return;
        }
        it1++;
        it2++;
    }
    cout<<"Yes"<<endl;
}

int main() {
ios::sync_with_stdio(0);
std::cin.tie(0);
std::cout.tie(0);
ll t =1;
cin>>t;
while(t--) solve();
return 0;
}