ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2062C - Cirno and Operations
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
#define endl '\n'
#define int long long
using namespace std;
using i64 = long long;

void solve() {
    int n; cin >> n;
    int sum = 0;
    // cout << n; printf("\n");
    vector<int> a(n);
    for (int i = 0;i < n;i++) cin >> a[i], sum += a[i];
    if (n == 1) {
        cout << sum << endl;
        return ;
    }
    vector<int> diff = a;
    for (int i = 1;i <= n;i++) {
        vector<int> ndiff;
        for (int j = 1;j < diff.size();j++) {
            ndiff.emplace_back(diff[j] - diff[j - 1]);
        }
        // for (int j = 0;j < ndiff.size();j++) {
        //     cout << ndiff[j] << " \n"[j == ndiff.size() - 1];
        // }
        diff = ndiff;
    }
    cout << max(abs(diff[0]), sum) << endl;
}

signed main() {
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    int T = 1; cin >> T;
    while (T--) solve();
    return 0;
}
Problem: 2062C - Cirno and Operations
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 6):
#include <bits/stdc++.h>
#define endl '\n'
#define int long long
using namespace std;
using i64 = long long;

void solve() {
    int n; cin >> n;
    int sum = 0;
    // cout << n; printf("\n");
    vector<int> a(n);
    for (int i = 0;i < n;i++) cin >> a[i], sum += a[i];
    vector<int> diff = a;
    for (int i = 1;i <= n;i++) {
        vector<int> ndiff;
        for (int j = 1;j < diff.size();j++) {
            ndiff.emplace_back(diff[j] - diff[j - 1]);
        }
        if (ndiff.empty()) break;
        // for (int j = 0;j < ndiff.size();j++) {
        //     cout << ndiff[j] << " \n"[j == ndiff.size() - 1];
        // }
        if (ndiff.size() > 1) 
            sum = max(sum, abs(ndiff.back() - ndiff.front()));
        else sum = max(sum, abs(ndiff[0]));
        diff = ndiff;
    }
    cout << sum << endl;
    // cout << max(abs(diff[0]), sum) << endl;
}

signed main() {
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    int T = 1; cin >> T;
    while (T--) solve();
    return 0;
}

Submission (verdict: Accepted):
#include <bits/stdc++.h>
#define endl '\n'
#define int long long
using namespace std;
using i64 = long long;

void solve() {
    int n; cin >> n;
    int sum = 0;
    // cout << n; printf("\n");
    vector<int> a(n);
    for (int i = 0;i < n;i++) cin >> a[i], sum += a[i];
    vector<int> diff = a;
    for (int i = 1;i <= n;i++) {
        vector<int> ndiff;
        int tmp = 0;
        for (int j = 1;j < diff.size();j++) {
            ndiff.emplace_back(diff[j] - diff[j - 1]);
            tmp += diff[j] - diff[j - 1];
        }
        if (ndiff.empty()) break;
        // for (int j = 0;j < ndiff.size();j++) {
        //     cout << ndiff[j] << " \n"[j == ndiff.size() - 1];
        // }
        // if (ndiff.size() > 1) 
        //     sum = max(sum, abs(ndiff.back() - ndiff.front()));
        sum = max(sum, abs(tmp));
        diff = ndiff;
    }
    cout << sum << endl;
    // cout << max(abs(diff[0]), sum) << endl;
}

signed main() {
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    int T = 1; cin >> T;
    while (T--) solve();
    return 0;
}
Problem: 2062C - Cirno and Operations
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
#define endl '\n'
#define int long long
using namespace std;
using i64 = long long;

void solve() {
    int n; cin >> n;
    int sum = 0;
    // cout << n; printf("\n");
    vector<int> a(n);
    for (int i = 0;i < n;i++) cin >> a[i], sum += a[i];
    if (n == 1) {
        cout << sum << endl;
        return ;
    }
    vector<int> diff = a;
    for (int i = 1;i <= n;i++) {
        vector<int> ndiff;
        for (int j = 1;j < diff.size();j++) {
            ndiff.emplace_back(diff[j] - diff[j - 1]);
        }
        // for (int j = 0;j < ndiff.size();j++) {
        //     cout << ndiff[j] << " \n"[j == ndiff.size() - 1];
        // }
        diff = ndiff;
    }
    cout << max(abs(diff[0]), sum) << endl;
}

signed main() {
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    int T = 1; cin >> T;
    while (T--) solve();
    return 0;
}

Submission (verdict: Wrong answer on test 6):
#include <bits/stdc++.h>
#define endl '\n'
#define int long long
using namespace std;
using i64 = long long;

void solve() {
    int n; cin >> n;
    int sum = 0;
    // cout << n; printf("\n");
    vector<int> a(n);
    for (int i = 0;i < n;i++) cin >> a[i], sum += a[i];
    vector<int> diff = a;
    for (int i = 1;i <= n;i++) {
        vector<int> ndiff;
        for (int j = 1;j < diff.size();j++) {
            ndiff.emplace_back(diff[j] - diff[j - 1]);
        }
        if (ndiff.empty()) break;
        // for (int j = 0;j < ndiff.size();j++) {
        //     cout << ndiff[j] << " \n"[j == ndiff.size() - 1];
        // }
        if (ndiff.size() > 1) 
            sum = max(sum, abs(ndiff.back() - ndiff.front()));
        else sum = max(sum, abs(ndiff[0]));
        diff = ndiff;
    }
    cout << sum << endl;
    // cout << max(abs(diff[0]), sum) << endl;
}

signed main() {
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    int T = 1; cin >> T;
    while (T--) solve();
    return 0;
}
Problem: 2063C - Remove Exactly Two
Language: C++23 (GCC 14-64, msys2)

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

const int inf = INT_MAX;
const int mod = 998244353;

void solve() {
    int n; cin >> n;
    vector<vector<int>> adj(n + 1);
    vector<int> deg(n + 1);
    vector<int> mx(n + 1), dp(n + 1);
    for (int i = 1, u, v;i < n;i++) {
        cin >> u >> v;
        adj[u].emplace_back(v);
        adj[v].emplace_back(u);
        deg[u] += 1, deg[v] += 1;
    }
    auto dfs = [&](auto &&self, int u, int pre) -> void {
        int maxdeg = 0;
        for (auto &v : adj[u]) {
            if (v == pre) continue;
            self(self, v, u);
            dp[u] = max(dp[u], dp[v]);
            dp[u] = max(deg[u] + deg[v] - 2, dp[u]);
            dp[u] = max(dp[u], deg[u] + mx[v] - 1);
            dp[u] = max(dp[u], deg[v] + maxdeg - 1);
            mx[u] = max({mx[u], mx[v], deg[v]});
            maxdeg = max(maxdeg, deg[v]);
        }
    };
    dfs(dfs, 1, 0);
    cout << dp[1] << endl;
} 

signed main() {
    ios::sync_with_stdio(false), cin.tie(0);
    int T = 1; cin >> T;
    while (T--) solve();
    return 0;
}

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

const int inf = INT_MAX;
const int mod = 998244353;

void solve() {
    int n; cin >> n;
    vector<vector<int>> adj(n + 1);
    vector<int> deg(n + 1);
    vector<int> mx(n + 1), dp(n + 1);
    for (int i = 1, u, v;i < n;i++) {
        cin >> u >> v;
        adj[u].emplace_back(v);
        adj[v].emplace_back(u);
        deg[u] += 1, deg[v] += 1;
    }
    auto dfs = [&](auto &&self, int u, int pre) -> void {
        int maxdeg = 0, maxdeg2 = 0;
        for (auto &v : adj[u]) {
            if (v == pre) continue;
            self(self, v, u);
            dp[u] = max(dp[u], dp[v]);
            dp[u] = max(deg[u] + deg[v] - 2, dp[u]);
            dp[u] = max(dp[u], deg[u] + mx[v] - 1);
            dp[u] = max(dp[u], deg[v] + maxdeg - 1);
            dp[u] = max(dp[u], maxdeg2 + deg[v] - 1);
            dp[u] = max(dp[u], mx[v] + maxdeg - 1);
            mx[u] = max({mx[u], mx[v], deg[v]});
            maxdeg2 = max(maxdeg2, mx[u]); 
            maxdeg = max(maxdeg, deg[v]);
        }
    };
    dfs(dfs, 1, 0);
    cout << dp[1] << endl;
} 

signed main() {
    ios::sync_with_stdio(false), cin.tie(0);
    int T = 1; cin >> T;
    while (T--) solve();
    return 0;
}
Problem: 2063C - Remove Exactly Two
Language: C++23 (GCC 14-64, msys2)

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

const int inf = INT_MAX;
const int mod = 998244353;

void solve() {
    int n; cin >> n;
    vector<vector<int>> adj(n + 1);
    vector<int> deg(n + 1);
    vector<int> mx(n + 1), dp(n + 1);
    for (int i = 1, u, v;i < n;i++) {
        cin >> u >> v;
        adj[u].emplace_back(v);
        adj[v].emplace_back(u);
        deg[u] += 1, deg[v] += 1;
    }
    auto dfs = [&](auto &&self, int u, int pre) -> void {
        int maxdeg = 0, maxdeg2 = 0;
        for (auto &v : adj[u]) {
            if (v == pre) continue;
            self(self, v, u);
            dp[u] = max(dp[u], dp[v]);
            dp[u] = max(deg[u] + deg[v] - 2, dp[u]);
            dp[u] = max(dp[u], deg[u] + mx[v] - 1);
            dp[u] = max(dp[u], deg[v] + maxdeg - 1);
            dp[u] = max(dp[u], maxdeg2 + deg[v] - 1);
            dp[u] = max(dp[u], mx[v] + maxdeg - 1);
            mx[u] = max({mx[u], mx[v], deg[v]});
            maxdeg2 = max(maxdeg2, mx[u]); 
            maxdeg = max(maxdeg, deg[v]);
        }
    };
    dfs(dfs, 1, 0);
    cout << dp[1] << endl;
} 

signed main() {
    ios::sync_with_stdio(false), cin.tie(0);
    int T = 1; cin >> T;
    while (T--) solve();
    return 0;
}

Submission (verdict: Accepted):
#include <bits/stdc++.h>
#define endl '\n'
#define int long long
using namespace std;

const int inf = INT_MAX;
const int mod = 998244353;

void solve() {
    int n; cin >> n;
    vector<vector<int>> adj(n + 1);
    vector<int> deg(n + 1);
    vector<int> mx(n + 1), dp(n + 1);
    for (int i = 1, u, v;i < n;i++) {
        cin >> u >> v;
        adj[u].emplace_back(v);
        adj[v].emplace_back(u);
        deg[u] += 1, deg[v] += 1;
    }
    auto dfs = [&](auto &&self, int u, int pre) -> void {
        int maxdeg = 0, maxdeg2 = 0;
        for (auto &v : adj[u]) {
            if (v == pre) continue;
            self(self, v, u);
            dp[u] = max(dp[u], dp[v]);
            dp[u] = max(deg[u] + deg[v] - 2, dp[u]);
            dp[u] = max(dp[u], deg[u] + mx[v] - 1);
            dp[u] = max(dp[u], deg[v] + maxdeg - 1);
            dp[u] = max(dp[u], maxdeg2 + deg[v] - 1);
            dp[u] = max(dp[u], mx[v] + maxdeg - 1);
            dp[u] = max(dp[u], mx[v] + maxdeg2 - 1);
            mx[u] = max({mx[u], mx[v], deg[v]});
            maxdeg2 = max(maxdeg2, mx[u]); 
            maxdeg = max(maxdeg, deg[v]);
        }
    };
    dfs(dfs, 1, 0);
    cout << dp[1] << endl;
} 

signed main() {
    ios::sync_with_stdio(false), cin.tie(0);
    int T = 1; cin >> T;
    while (T--) solve();
    return 0;
}
Problem: 2063C - Remove Exactly Two
Language: C++23 (GCC 14-64, msys2)

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

const int inf = INT_MAX;
const int mod = 998244353;

void solve() {
    int n; cin >> n;
    vector<vector<int>> adj(n + 1);
    vector<int> deg(n + 1);
    vector<int> mx(n + 1), dp(n + 1);
    for (int i = 1, u, v;i < n;i++) {
        cin >> u >> v;
        adj[u].emplace_back(v);
        adj[v].emplace_back(u);
        deg[u] += 1, deg[v] += 1;
    }
    auto dfs = [&](auto &&self, int u, int pre) -> void {
        for (auto &v : adj[u]) {
            if (v == pre) continue;
            self(self, v, u);
            dp[u] = max(dp[u], dp[v]);
            dp[u] = max(deg[u] + deg[v] - 2, dp[u]);
            dp[u] = max(dp[u], deg[u] + mx[v] - 1);
            mx[u] = max({mx[u], mx[v], deg[v]});
        }
    };
    dfs(dfs, 1, 0);
    cout << dp[1] << endl;
} 

signed main() {
    ios::sync_with_stdio(false), cin.tie(0);
    int T = 1; cin >> T;
    while (T--) solve();
    return 0;
}

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

const int inf = INT_MAX;
const int mod = 998244353;

void solve() {
    int n; cin >> n;
    vector<vector<int>> adj(n + 1);
    vector<int> deg(n + 1);
    vector<int> mx(n + 1), dp(n + 1);
    for (int i = 1, u, v;i < n;i++) {
        cin >> u >> v;
        adj[u].emplace_back(v);
        adj[v].emplace_back(u);
        deg[u] += 1, deg[v] += 1;
    }
    auto dfs = [&](auto &&self, int u, int pre) -> void {
        vector<int> degs;
        for (auto &v : adj[u]) {
            if (v == pre) continue;
            self(self, v, u);
            degs.emplace_back(deg[v]);
            dp[u] = max(dp[u], dp[v]);
            dp[u] = max(deg[u] + deg[v] - 2, dp[u]);
            dp[u] = max(dp[u], deg[u] + mx[v] - 1);
            mx[u] = max({mx[u], mx[v], deg[v]});
        }
        sort(degs.begin(), degs.end(), greater<int>());
        if (degs.size() >= 2)
            dp[u] = max(dp[u], degs[0] + degs[1] - 1);
    };
    dfs(dfs, 1, 0);
    cout << dp[1] << endl;
} 

signed main() {
    ios::sync_with_stdio(false), cin.tie(0);
    int T = 1; cin >> T;
    while (T--) solve();
    return 0;
}
Problem: 2063C - Remove Exactly Two
Language: C++23 (GCC 14-64, msys2)


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

const int inf = INT_MAX;
const int mod = 998244353;

void solve() {
    int n; cin >> n;
    vector<vector<int>> adj(n + 1);
    vector<int> deg(n + 1);
    vector<int> mx(n + 1), dp(n + 1);
    for (int i = 1, u, v;i < n;i++) {
        cin >> u >> v;
        adj[u].emplace_back(v);
        adj[v].emplace_back(u);
        deg[u] += 1, deg[v] += 1;
    }
    auto dfs = [&](auto &&self, int u, int pre) -> void {
        for (auto &v : adj[u]) {
            if (v == pre) continue;
            self(self, v, u);
            dp[u] = max(dp[u], dp[v]);
            dp[u] = max(deg[u] + deg[v] - 2, dp[u]);
            dp[u] = max(dp[u], deg[u] + mx[v] - 1);
            mx[u] = max({mx[u], mx[v], deg[v]});
        }
    };
    dfs(dfs, 1, 0);
    cout << dp[1] << endl;
} 

signed main() {
    ios::sync_with_stdio(false), cin.tie(0);
    int T = 1; cin >> T;
    while (T--) solve();
    return 0;
}
Problem: 2063C - Remove Exactly Two
Language: C++23 (GCC 14-64, msys2)

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

const int inf = INT_MAX;
const int mod = 998244353;

void solve() {
    int n; cin >> n;
    vector<vector<int>> adj(n + 1);
    vector<int> deg(n + 1);
    vector<int> mx(n + 1), dp(n + 1);
    for (int i = 1, u, v;i < n;i++) {
        cin >> u >> v;
        adj[u].emplace_back(v);
        adj[v].emplace_back(u);
        deg[u] += 1, deg[v] += 1;
    }
    auto dfs = [&](auto &&self, int u, int pre) -> void {
        vector<int> degs;
        for (auto &v : adj[u]) {
            if (v == pre) continue;
            self(self, v, u);
            degs.emplace_back(deg[v]);
            dp[u] = max(dp[u], dp[v]);
            dp[u] = max(deg[u] + deg[v] - 2, dp[u]);
            dp[u] = max(dp[u], deg[u] + mx[v] - 1);
            mx[u] = max({mx[u], mx[v], deg[v]});
        }
        sort(degs.begin(), degs.end(), greater<int>());
        if (degs.size() >= 2)
            dp[u] = max(dp[u], degs[0] + degs[1] - 1);
    };
    dfs(dfs, 1, 0);
    cout << dp[1] << endl;
} 

signed main() {
    ios::sync_with_stdio(false), cin.tie(0);
    int T = 1; cin >> T;
    while (T--) solve();
    return 0;
}

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

const int inf = INT_MAX;
const int mod = 998244353;

void solve() {
    int n; cin >> n;
    vector<vector<int>> adj(n + 1);
    vector<int> deg(n + 1);
    vector<int> mx(n + 1), dp(n + 1);
    for (int i = 1, u, v;i < n;i++) {
        cin >> u >> v;
        adj[u].emplace_back(v);
        adj[v].emplace_back(u);
        deg[u] += 1, deg[v] += 1;
    }
    auto dfs = [&](auto &&self, int u, int pre) -> void {
        int maxdeg = 0;
        for (auto &v : adj[u]) {
            if (v == pre) continue;
            self(self, v, u);
            dp[u] = max(dp[u], dp[v]);
            dp[u] = max(deg[u] + deg[v] - 2, dp[u]);
            dp[u] = max(dp[u], deg[u] + mx[v] - 1);
            dp[u] = max(dp[u], deg[v] + maxdeg - 1);
            mx[u] = max({mx[u], mx[v], deg[v]});
            maxdeg = max(maxdeg, deg[v]);
        }
    };
    dfs(dfs, 1, 0);
    cout << dp[1] << endl;
} 

signed main() {
    ios::sync_with_stdio(false), cin.tie(0);
    int T = 1; cin >> T;
    while (T--) solve();
    return 0;
}
Problem: 2063B - Subsequence Update
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 8):
#include <bits/stdc++.h>
#define int long long
using namespace std;
constexpr int INF = 0x3f3f3f3f;

void solve()
{
    int n,l,r;
    cin >> n >> l >> r;
    int len = r - l + 1;

    vector<int> q(n + 1);
    for(int i = 1; i <= n; i ++) cin >> q[i];
    auto left = q,right = q;

    sort(left.begin(),left.begin() + r + 1);
    sort(right.begin() + l,right.end());

    int res = INF,sum = 0;
    for(int i = 1; i <= len; i ++) sum += left[i];

    res = min(res,sum); sum = 0;
    for(int i = l; i <= len + l - 1; i ++) sum += right[i];
    res = min(res,sum);

    cout << res << endl;
}

signed main()
{
    int _ = 1;
    cin >> _;
    while(_ --) solve();
    return 0;
}
// 1 1 1 1 3 5 6


Submission (verdict: Accepted):
#include <bits/stdc++.h>
#define int long long
using namespace std;
constexpr int INF = 0x3f3f3f3f;

void solve()
{
    int n,l,r;
    cin >> n >> l >> r;
    int len = r - l + 1;

    vector<int> q(n + 1);
    for(int i = 1; i <= n; i ++) cin >> q[i];
    auto left = q,right = q;

    sort(left.begin(),left.begin() + r + 1);
    sort(right.begin() + l,right.end());

    int sum = 0;
    for(int i = 1; i <= len; i ++) sum += left[i];

    int res = sum; sum = 0;
    for(int i = l; i <= len + l - 1; i ++) sum += right[i];
    res = min(res,sum);

    cout << res << endl;
}

signed main()
{
    int _ = 1;
    cin >> _;
    while(_ --) solve();
    return 0;
}
// 1 1 1 1 3 5 6
Problem: 2063B - Subsequence Update
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
#define int long long
using namespace std;
constexpr int INF = 0x3f3f3f3f;

void solve()
{
    int n,l,r;
    cin >> n >> l >> r;
    int len = r - l + 1;

    vector<int> q(n + 1);
    for(int i = 1; i <= n; i ++) cin >> q[i];
    auto left = q,right = q;

    sort(left.begin(),left.begin() + r);
    sort(right.begin() + l,right.end());

    int res = INF,sum = 0;
    for(int i = 1; i <= len; i ++) sum += left[i];

    res = min(res,sum); sum = 0;
    for(int i = l; i <= len + l - 1; i ++) sum += right[i];
    res = min(res,sum);

    cout << res << endl;
}

signed main()
{
    int _ = 1;
    cin >> _;
    while(_ --) solve();
    return 0;
}
// 1 1 1 1 3 5 6
Problem: 2063B - Subsequence Update
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
#define int long long
using namespace std;
constexpr int INF = 0x3f3f3f3f;

void solve()
{
    int n,l,r;
    cin >> n >> l >> r;
    int len = r - l + 1;

    vector<int> q(n + 1);
    for(int i = 1; i <= n; i ++) cin >> q[i];
    auto left = q,right = q;

    sort(left.begin(),left.begin() + r);
    sort(right.begin() + l,right.end());

    int res = INF,sum = 0;
    for(int i = 1; i <= len; i ++) sum += left[i];

    res = min(res,sum); sum = 0;
    for(int i = l; i <= len + l - 1; i ++) sum += right[i];
    res = min(res,sum);

    cout << res << endl;
}

signed main()
{
    int _ = 1;
    cin >> _;
    while(_ --) solve();
    return 0;
}
// 1 1 1 1 3 5 6


Submission (verdict: Wrong answer on test 8):
#include <bits/stdc++.h>
#define int long long
using namespace std;
constexpr int INF = 0x3f3f3f3f;

void solve()
{
    int n,l,r;
    cin >> n >> l >> r;
    int len = r - l + 1;

    vector<int> q(n + 1);
    for(int i = 1; i <= n; i ++) cin >> q[i];
    auto left = q,right = q;

    sort(left.begin(),left.begin() + r + 1);
    sort(right.begin() + l,right.end());

    int res = INF,sum = 0;
    for(int i = 1; i <= len; i ++) sum += left[i];

    res = min(res,sum); sum = 0;
    for(int i = l; i <= len + l - 1; i ++) sum += right[i];
    res = min(res,sum);

    cout << res << endl;
}

signed main()
{
    int _ = 1;
    cin >> _;
    while(_ --) solve();
    return 0;
}
// 1 1 1 1 3 5 6
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;
#define endl "\n"
typedef pair<int,int> pi;
const int mod=998244353;
#define int long long
const int M = 4e5 + 10;
int  power(int a, int b){
    if (b==0) return 1;
    int t =power(a,b/2);
    return (b%2?t*t%mod*a%mod:t*t%mod);
 }
 bool f(int x,map<int,int>&mp){
    if(mp[x]>0){
        mp[x]--;
        return true;
    }
    if(x==0){return false;}
    int flag=f(x/2,mp)&&f((x+1)/2,mp);
    return flag;
 }
 void solve(){ 
   int n,m;
   cin>>n>>m;
   vector<int>a(n),b(m);
   map<int,int>mp;
   for(int i=0;i<n;i++){cin>>a[i];mp[a[i]]++;}
   for(int i=0;i<m;i++){
    cin>>b[i];
   }
   sort(a.begin(),a.end());
   sort(b.begin(),b.end());
   for(int i=0;i<m;i++){
     if(!f(b[i],mp)){cout<<"NO"<<endl;return;}
   }
   for(int i=0;i<n;i++){
     if(mp[a[i]]){cout<<"NO"<<endl;return;}
   }
   cout<<"YES"<<endl;
 }
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T=1;
    cin >> T;
    while (T--) {
        solve();
    }
} 

Submission (verdict: Wrong answer on test 3):
#include <bits/stdc++.h>

using namespace std;
const int NMAX = 2e5 + 5;

int a[NMAX], b[NMAX];

map <int, int> fr;

priority_queue <int> pq;

int main()
{

    cin.tie(0);
    ios_base :: sync_with_stdio(false);

    int tt;
    cin >> tt;

    while(tt --)
    {
        int n, m;

        cin >> n >> m;

        fr.clear();
        while(!pq.empty()) pq.pop();

        int s1 = 0, s2 = 0;

        for(int i = 1; i <= n; i ++) {cin >> a[i]; s1 += a[i];}
        for(int i = 1; i <= m; i ++) {cin >> b[i]; s2 += b[i];}

        for(int i = 1; i <= n; i ++) fr[a[i]] ++;

        for(int i = 1; i <= m; i ++) pq.push(b[i]);

        if(s1 != s2)
        {
            cout << "NO" << '\n';
            continue;
        }


        while(!pq.empty())
        {
            int val = pq.top();
            pq.pop();

            if(fr.find(val) == fr.end() || fr[val] == 0)
            {
                if(val == 1) break;
                int val1 = ceil(val / 2.00);
                int val2 = floor(val / 2.00);

                pq.push(val1), pq.push(val2);
            }
            else
            {
                fr[val] --;
            }
        }

        bool ok = true;
        if(pq.size()) ok = false;

        for(auto it : fr)
        {
            if(it.second)
            {
                ok = false;
            }
        }

        cout << (ok ? "YES" : "NO") << '\n';
    }

    return 0;
}