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 long double ld;
typedef complex<ld> cd;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef unordered_map<ll,ll> ull;

#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define endl '\n'
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define F first
#define S second
#define REP(i, a, b) for (int i = (a); i < (b); ++i)
#define REPR(i, a, b) for (int i = (a); i > (b); --i)
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())
#define REVERSE(v) reverse(all(v))
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define SQR(x) ((ll)(x) * (x))
#define RESET(a, b) memset(a, b, sizeof(a))
#define yes cout<<"YES"<<"\n"
#define no cout<<"NO"<<"\n"
#define input(a, n) for(int i = 0; i < n; i++) cin >> a[i]

const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll LLINF = 1e18;
const double PI = acos(-1.0);
const double EPS = 1e-9;

#define DEBUG
#ifdef DEBUG
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#define dbg(x) cerr << #x << " = " << x << endl
#endif

template <typename T>
void print(T t) { cout << t << "\n"; }

template <typename T, typename... Args>
void print(T t, Args... args) {
    cout << t << " ";
    print(args...);
}

template <typename T>
void printVector(const vector<T>& v) {
    for (const T& x : v) cout << x << " ";
    cout << "\n";
}


ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll mod_add(ll a, ll b, ll m) { return (a % m + b % m) % m; }
ll mod_sub(ll a, ll b, ll m) { return (a % m - b % m + m) % m; }
ll mod_mul(ll a, ll b, ll m) { return ((a % m) * (b % m)) % m; }
ll mod_pow(ll b, ll p, ll m) {
    ll r = 1;
    while (p) {
        if (p & 1) r = mod_mul(r, b, m);
        b = mod_mul(b, b, m);
        p >>= 1;
    }
    return r;
}


void solve() {
    ll n,m;
    cin>>n>>m;
    vll a(n,0),b(m,0);
    unordered_map<ll,ll>mpp1,mpp2;
    REP(i,0,n)
    {
        cin>>a[i];
        mpp1[a[i]]++;
    }
    REP(j,0,m)
    {
        cin>>b[j];
        mpp2[b[j]]++;
    }
    multiset<ll>s1,s2;
    for(int i=0;i<m;i++)
    {
        ll num=b[i];
        if((mpp1.find(num)!=mpp1.end()) && (mpp2.find(num)!=mpp2.end()))
        {
            mpp1[num]--;
            mpp2[num]--;
            if(mpp1[num]==0) mpp1.erase(num);
            if(mpp2[num]==0) mpp2.erase(num);
        }
        else 
        {
            s2.insert(b[i]);
        }
    }
    for(int i=0;i<n;i++)
    {
        if(!s2.count(a[i]))
        {
            if(mpp1[a[i]]>0)
            {
                mpp1[a[i]]--;
                if(mpp1[a[i]]==0) mpp1.erase(a[i]);
                s1.insert(a[i]);
            }
        }
    }
    // cout<<s1.size()<<" "<<s2.size()<<"\n";
    vll v1(all(s1)),v2(all(s2));
    // for(auto it:v1)
    // {
    //     cout<<it<<" ";
    // }
    // cout<<"\n";
    int i=0,j=0;
    ll sum=0;
    ll last=-1;
    while(j<(v2.size()))
    {
        while(i<(v1.size()) && (sum<v2[j]))
        {
            if(sum==0)
             {
                sum+=v1[i];
                last=v1[i];
                i++;
             }
            else if(sum>0)
            {
                if(abs(v1[i]-last)<=1 || (abs(v1[i]-sum))<=1)
                {
                    sum+=v1[i];
                    last=v1[i];
                    i++;
                }
                else
                {
                    cout<<"No"<<"\n";
                    return;
                }
            }
        }
        // cout<<sum<<endl;
        if(sum!=(v2[j]))
        {
            cout<<"No"<<"\n";
            return;
        }
        else 
        {
            sum=0;
            j++;
        }
    }
    if(s2.size()==0 && s1.size()!=0)
    {
        cout<<"No"<<"\n";
        return;
    }
    cout<<"Yes"<<"\n";

}

int main() {
    fastio;  
    
    
    int t = 1;
    cin >> t;  
    while (t--) {
        solve();
    }
    return 0;
}

Submission (verdict: Accepted):
#include <bits/stdc++.h>
using namespace std;


typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef unordered_map<ll,ll> ull;

#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define endl '\n'
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define F first
#define S second
#define REP(i, a, b) for (int i = (a); i < (b); ++i)
#define REPR(i, a, b) for (int i = (a); i > (b); --i)
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())
#define REVERSE(v) reverse(all(v))
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define SQR(x) ((ll)(x) * (x))
#define RESET(a, b) memset(a, b, sizeof(a))
#define yes cout<<"YES"<<"\n"
#define no cout<<"NO"<<"\n"
#define input(a, n) for(int i = 0; i < n; i++) cin >> a[i]

const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll LLINF = 1e18;
const double PI = acos(-1.0);
const double EPS = 1e-9;

#define DEBUG
#ifdef DEBUG
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#define dbg(x) cerr << #x << " = " << x << endl
#endif

template <typename T>
void print(T t) { cout << t << "\n"; }

template <typename T, typename... Args>
void print(T t, Args... args) {
    cout << t << " ";
    print(args...);
}

template <typename T>
void printVector(const vector<T>& v) {
    for (const T& x : v) cout << x << " ";
    cout << "\n";
}


ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll mod_add(ll a, ll b, ll m) { return (a % m + b % m) % m; }
ll mod_sub(ll a, ll b, ll m) { return (a % m - b % m + m) % m; }
ll mod_mul(ll a, ll b, ll m) { return ((a % m) * (b % m)) % m; }
ll mod_pow(ll b, ll p, ll m) {
    ll r = 1;
    while (p) {
        if (p & 1) r = mod_mul(r, b, m);
        b = mod_mul(b, b, m);
        p >>= 1;
    }
    return r;
}


void solve() {
    ll n,m;
    cin>>n>>m;
    vll a(n,0),b(m,0);
    multiset<ll>s1,s2;
    REP(i,0,n)
    {
        cin>>a[i];
        s1.insert(a[i]);
    }
    REP(j,0,m)
    {
        cin>>b[j];
        s2.insert(b[j]);
    }
    // multiset<ll>s1,s2;
    for(int i=0;i<=(n-m);i++)
    {
        while(!(s1.empty()) && !(s2.empty()))
        {
            ll num1=*(s1.rbegin());
            ll num2=*(s2.rbegin());
            if(num1==num2)
            {
                s1.erase(s1.find(num1));
                s2.erase(s2.find(num1));
            }
            else break;
        }
        if(s1.empty() && s2.empty())
        {
            yes;
            return;
        }
        if(!s2.empty())
        {
        ll last=*(s2.rbegin());
        s2.erase(s2.find(last));
        s2.insert(last/2);
        s2.insert((last+1)/2);
        }
    }
    if(s1.empty() && s2.empty())
    {
        yes;
        return;
    }
    else no;

}

int main() {
    fastio;  
    
    
    int t = 1;
    cin >> t;  
    while (t--) {
        solve();
    }
    return 0;
}