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
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
#define vpp vector<pair<int, int>>
#define vii vector<vector<int>>
#define pb push_back
#define fast_io                       \
    ios_base::sync_with_stdio(false); \
    cin.tie(0);                       \
    cout.tie(0);
#define fr(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define frr(i, a, b) for (int i = (int)a; i >= (int)b; --i)
#define mx(v) *max_element(all(v))
#define mn(v) *min_element(all(v))
#define ff first
#define ss second
#define in insert
#define dbg(x) cout << #x << " = " << x << endl;
#define rd(n) \
    int n;    \
    cin >> n;
#define bs binary_search
#define setbits(n) __builtin_popcount((int)n)
#define mod 1000000007
#define vti(a, n) \
    vi a(n);      \
    fr(i, 0, n) cin >> a[(int)i];
const int N = 1e9 + 7;

typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ld, ld> pld;

/* ----------------------------------Things get better by time, hope for the best-----------------*/

void solve()
{
    int n, m;
    cin >> n >> m;
    vi a(n), b(m);
    fr(i, 0, n)
    {
        cin >> a[i];
    }
    fr(i, 0, m)
    {
        cin >> b[i];
    }
    sort(all(a));
    sort(all(b));
    int i = 0, j = 0;
    while (i < n && j < m)
    {
        while (i < n && a[i] < b[j])
            i++;
        if (i < n && a[i] == b[j])
        {
            b[j] = -1;
            a[i] = -1;
            i++;
        }
        j++;
    }
    // fr(i, 0, n) cout << a[i] << " ";
    // cout << endl;
    // fr(j, 0, m) cout << b[j] << " ";
    // cout << endl;
    i = 0, j = 0;
    while (i < n && j < m)
    {
        while (i < n && a[i] == -1)
            i++;
        while (j < m && b[j] == -1)
            j++;
        int sum = 0, prev = 0;
        if (i < n)
            prev = a[i] - 1;
        // cout << prev << " ";
        while (i < n && j < m && sum < b[j])
        {
            if (a[i] == -1)
            {
                i++;
                continue;
            }
            if (abs(a[i] - prev) > 1)
                break;
            sum += a[i];
            prev = sum;
            i++;
        }
        if (j == m && sum > 0)
        {
            cout << "No\n";
            return;
        }
        if (j == m)
            break;
        if (sum != b[j])
        {
            // cout << sum << " " << b[j] << " " << i << " ";
            cout << "No\n";
            return;
        }
        else
        {
            j++;
        }
    }
    if (i == n && j == m)
    {
        cout << "Yes\n";
    }
    else
        cout << "No\n";
}
int32_t main()
{
    fast_io;
    int t = 1;
    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
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
#define vpp vector<pair<int, int>>
#define vii vector<vector<int>>
#define pb push_back
#define fast_io                       \
    ios_base::sync_with_stdio(false); \
    cin.tie(0);                       \
    cout.tie(0);
#define fr(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define frr(i, a, b) for (int i = (int)a; i >= (int)b; --i)
#define mx(v) *max_element(all(v))
#define mn(v) *min_element(all(v))
#define ff first
#define ss second
#define in insert
#define dbg(x) cout << #x << " = " << x << endl;
#define rd(n) \
    int n;    \
    cin >> n;
#define bs binary_search
#define setbits(n) __builtin_popcount((int)n)
#define mod 1000000007
#define vti(a, n) \
    vi a(n);      \
    fr(i, 0, n) cin >> a[(int)i];
const int N = 1e9 + 7;

typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ld, ld> pld;

/* ----------------------------------Things get better by time, hope for the best-----------------*/

void solve()
{
    int n, m;
    cin >> n >> m;
    vi a(n), b(m);
    fr(i, 0, n)
    {
        cin >> a[i];
    }
    fr(i, 0, m)
    {
        cin >> b[i];
    }
    sort(all(a));
    sort(all(b));
    int i = 0, j = 0;
    while (i < n && j < m)
    {
        while (i < n && a[i] < b[j])
            i++;
        if (i < n && a[i] == b[j])
        {
            b[j] = -1;
            a[i] = -1;
            i++;
        }
        j++;
    }
    // fr(i, 0, n) cout << a[i] << " ";
    // cout << endl;
    // fr(j, 0, m) cout << b[j] << " ";
    // cout << endl;
    i = 0, j = 0;
    while (i < n && j < m)
    {
        while (i < n && a[i] == -1)
            i++;
        while (j < m && b[j] == -1)
            j++;
        int sum = 0, prev = 0;
        if (i < n)
            prev = a[i] - 1;
        // cout << prev << " ";
        while (i < n && j < m && sum < b[j])
        {
            if (a[i] == -1)
            {
                i++;
                continue;
            }
            if (abs(a[i] - prev) > 1)
                break;
            sum += a[i];
            prev = sum;
            i++;
        }
        if (j == m && sum > 0)
        {
            cout << "No\n";
            return;
        }
        if (j == m)
            break;
        if (sum != b[j])
        {
            // cout << sum << " " << b[j] << " " << i << " ";
            cout << "No\n";
            return;
        }
        else
        {
            j++;
        }
    }
    while (i < n && a[i] == -1)
        i++;
    while (j < m && b[j] == -1)
        j++;
    // cout << i << " " << j << endl;
    if (i == n && j == m)
    {
        cout << "Yes\n";
    }
    else
        cout << "No\n";
}
int32_t main()
{
    fast_io;
    int t = 1;
    cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}