ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2050B - Transfusion
Language: C++17 (GCC 7-32)

Previous submission (verdict: Time limit exceeded on test 3):
#include <bits/stdc++.h>

using  namespace std;

int main() {

    int t;cin >> t;

    while (t--) {

        int n;cin >> n;

        vector<int>v(n);

        int count = 0;

        for (int i = 0;i < n;i++){cin >> v[i];count += v[i];}

        if (count % n){cout << "NO" << endl;continue;}

        int sum = count / n;

        for (int i = 1;i < v.size() - 1;i++) {

            while (v[i - 1] != sum) {

                if (v[i - 1] < sum) {

                    v[i - 1]++;v[i + 1]--;

                }else {

                    v[i - 1]--;v[i + 1]++;

                }

            }

        }

        bool f = true;

        for (int i = 0;i < v.size();i++) {

            if (v[i] != sum){f = false;break;}

        }

        if (f)cout << "YES" << endl;else cout << "NO" << endl;

        v.clear();

    }

}

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

using  namespace std;

int main() {

    int t;cin >> t;

    while (t--) {

        int n;cin >> n;

        vector<int>v(n);

        int count = 0;

        for (int i = 0;i < n;i++){cin >> v[i];count += v[i];}

        if (count % n){cout << "NO" << endl;continue;}

        int sum = count / n;

        for (int i = 1;i < v.size() - 1;i++) {

            int j1,j2;

            if (v[i - 1] < sum && v[i + 1] > sum) {

                j1 = sum - v[i - 1];

                v[i - 1] += j1;

                v[i + 1] -= j1;

            }else if (v[i - 1] > sum && v[i + 1] < sum){

                j1 = v[i - 1] - sum;

                v[i - 1] -= j1;

                v[i + 1] += j1;

            }

        }

        bool f = true;

        for (int i = 0;i < v.size();i++) {

            if (v[i] != sum){f = false;break;}

        }

        if (f)cout << "YES" << endl;else cout << "NO" << endl;

        v.clear();

    }

}
Problem: 2050B - Transfusion
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>

using  namespace std;

int main() {

    int t;cin >> t;

    while (t--) {

        int n;cin >> n;

        vector<int>v(n);

        int count = 0;

        for (int i = 0;i < n;i++){cin >> v[i];count += v[i];}

        if (count % n){cout << "NO" << endl;continue;}

        int sum = count / n;

        for (int i = 1;i < v.size() - 1;i++) {

            int j1,j2;

            if (v[i - 1] < sum && v[i + 1] > sum) {

                j1 = sum - v[i - 1];

                v[i - 1] += j1;

                v[i + 1] -= j1;

            }else if (v[i - 1] > sum && v[i + 1] < sum){

                j1 = v[i - 1] - sum;

                v[i - 1] -= j1;

                v[i + 1] += j1;

            }

        }

        bool f = true;

        for (int i = 0;i < v.size();i++) {

            if (v[i] != sum){f = false;break;}

        }

        if (f)cout << "YES" << endl;else cout << "NO" << endl;

        v.clear();

    }

}

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

using  namespace std;

int main() {

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

    int t;cin >> t;

    while (t--) {

        int n;cin >> n;

        vector<int>v(n);

        int count = 0;

        for (int i = 0;i < n;i++){cin >> v[i];count += v[i];}

        if (count % n){cout << "NO" << endl;continue;}

        int sum = count / n;

        for (int i = 1;i < v.size() - 1;i++) {

            while (v[i - 1] != sum) {

                if (v[i - 1] < sum) {

                    v[i - 1]++;v[i + 1]--;

                }else {

                    v[i - 1]--;v[i + 1]++;

                }

            }

        }

        bool f = true;

        for (int i = 0;i < v.size();i++) {

            if (v[i] != sum){f = false;break;}

        }

        if (f)cout << "YES" << endl;else cout << "NO" << endl;

        v.clear();

    }

}
Problem: 2050B - Transfusion
Language: C++17 (GCC 7-32)


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

using  namespace std;

int main() {

    int t;cin >> t;

    while (t--) {

        int n;cin >> n;

        vector<int>v(n);

        int count = 0;

        for (int i = 0;i < n;i++){cin >> v[i];count += v[i];}

        if (count % n){cout << "NO" << endl;continue;}

        int sum = count / n;

        for (int i = 1;i < v.size() - 1;i++) {

            while (v[i - 1] != sum) {

                if (v[i - 1] < sum) {

                    v[i - 1]++;v[i + 1]--;

                }else {

                    v[i - 1]--;v[i + 1]++;

                }

            }

        }

        bool f = true;

        for (int i = 0;i < v.size();i++) {

            if (v[i] != sum){f = false;break;}

        }

        if (f)cout << "YES" << endl;else cout << "NO" << endl;

        v.clear();

    }

}
Problem: 2057C - Trip to the Olympiad
Language: C++20 (GCC 13-64)

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

typedef long long ll;
typedef pair<int, int> PII;

void solve()
{
    int l, r;
    cin >> l >> r;
    int m = 0;
    bool flag = false;
    for (int i = 30; i >= 0; i--)
    {
        int a = l >> i & 1, b = r >> i & 1;
        if (!flag)
        {
            if (a == b){
                if(a)
                    m += 1 << i;
            }
            else
                flag = true;
        }
        else
        {
            if((a == b && !a) || a != b)
                m += 1 << i;
        }
    }

    if(m <= l)
        m = l + 1;
    cout << l << ' ' << m << ' ' << r << endl;
}

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    // freopen("test.in", "r", stdin);

    int t = 1;
    cin >> t;
    while (t--)
        solve();

    return 0;
}

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

typedef long long ll;
typedef pair<int, int> PII;

void solve()
{
    int l, r;
    cin >> l >> r;
    int m = 0, n = 0;
    bool flag = false;
    for (int i = 30; i >= 0; i--)
    {
        int a = l >> i & 1, b = r >> i & 1;
        if (!flag)
        {
            if (a == b){
                if(a)
                    m += 1 << i,
                    n += 1 << i;
            }
            else
                flag = true,
                n += 1 << i;
        }
        else
        {
            if((a == b && !a) || a != b)
                m += 1 << i;
            if((a == b && !a))
                n += 1 << i;
        }
    }

    if(m <= l)
        m = l + 1;
    if(n >= r)
        n = r - 1;
    int sum1 = n ^ l + n ^ r, sum2 = m ^ l + m ^ r;
    if(sum1 > sum2)
        cout << l << ' ' << n << ' ' << r << endl;
    else
        cout << l << ' ' << m << ' ' << r << endl;
}

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    // freopen("test.in", "r", stdin);

    int t = 1;
    cin >> t;
    while (t--)
        solve();

    return 0;
}
Problem: 2057C - Trip to the Olympiad
Language: C++20 (GCC 13-64)


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

typedef long long ll;
typedef pair<int, int> PII;

void solve()
{
    int l, r;
    cin >> l >> r;
    int m = 0;
    bool flag = false;
    for (int i = 30; i >= 0; i--)
    {
        int a = l >> i & 1, b = r >> i & 1;
        if (!flag)
        {
            if (a == b){
                if(a)
                    m += 1 << i;
            }
            else
                flag = true;
        }
        else
        {
            if((a == b && !a) || a != b)
                m += 1 << i;
        }
    }

    if(m <= l)
        m = l + 1;
    cout << l << ' ' << m << ' ' << r << endl;
}

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    // freopen("test.in", "r", stdin);

    int t = 1;
    cin >> t;
    while (t--)
        solve();

    return 0;
}
Problem: 2057C - Trip to the Olympiad
Language: C++20 (GCC 13-64)

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

typedef long long ll;
typedef pair<int, int> PII;

void solve()
{
    int l, r;
    cin >> l >> r;
    int m = 0, n = 0;
    bool flag = false;
    for (int i = 30; i >= 0; i--)
    {
        int a = l >> i & 1, b = r >> i & 1;
        if (!flag)
        {
            if (a == b){
                if(a)
                    m += 1 << i,
                    n += 1 << i;
            }
            else
                flag = true,
                n += 1 << i;
        }
        else
        {
            if((a == b && !a) || a != b)
                m += 1 << i;
            if((a == b && !a))
                n += 1 << i;
        }
    }

    if(m <= l)
        m = l + 1;
    if(n >= r)
        n = r - 1;
    int sum1 = n ^ l + n ^ r, sum2 = m ^ l + m ^ r;
    if(sum1 > sum2)
        cout << l << ' ' << n << ' ' << r << endl;
    else
        cout << l << ' ' << m << ' ' << r << endl;
}

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    // freopen("test.in", "r", stdin);

    int t = 1;
    cin >> t;
    while (t--)
        solve();

    return 0;
}

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

typedef long long ll;
typedef pair<int, int> PII;

void solve()
{
    int l, r;
    cin >> l >> r;
    int m = 0, n = 0;
    bool flag = false;
    for (int i = 30; i >= 0; i--)
    {
        int a = l >> i & 1, b = r >> i & 1;
        if (!flag)
        {
            if (a == b){
                if(a)
                    m += 1 << i,
                    n += 1 << i;
            }
            else
                flag = true,
                n += 1 << i;
        }
        else
        {
            if((a == b && !a) || a != b)
                m += 1 << i;
            if((a == b && !a))
                n += 1 << i;
        }
    }

    if(m <= l)
        m = l + 1;
    if(n >= r)
        n = r - 1;
    int sum1 = (n ^ l) + (n ^ r), sum2 = (m ^ l) + (m ^ r);
    if(sum1 > sum2)
        cout << l << ' ' << n << ' ' << r << endl;
    else
        cout << l << ' ' << m << ' ' << r << endl;
}

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    // freopen("test.in", "r", stdin);

    int t = 1;
    cin >> t;
    while (t--)
        solve();

    return 0;
}
Problem: 2057B - Gorilla and the Exam
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Wrong answer on test 1):
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
    int t;
    cin>>t;
    while(t--){
    int n,k;
    cin>>n>>k;
    map<ll,ll>m;
    for(int i=0;i<n;i++){
        ll x;
        cin>>x;
        m[x]++;
    }
     vector<int>v;
     for(auto pr:m){
         v.push_back(pr.second);
     }
     sort(v.begin(),v.end());
     int sum=0;
     for(int i=0;i<n;i++){
         sum+=v[i];
         if(sum>k){
             sum-=v[i];
             break;
         }
     }
     cout<<v.size()-sum<<endl;
    }
}
Problem: 2057B - Gorilla and the Exam
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
    int t;
    cin>>t;
    while(t--){
    int n,k;
    cin>>n>>k;
    map<ll,ll>m;
    for(int i=0;i<n;i++){
        ll x;
        cin>>x;
        m[x]++;
    }
     vector<int>v;
     for(auto pr:m){
         v.push_back(pr.second);
     }
     sort(v.begin(),v.end());
     int sum=0,cnt=0;
     for(int i=0;i<n;i++){
         sum+=v[i];
         cnt++;
         if(sum>k||i==n-1){
            cnt--;
             break;
         }
     }
     cout<<v.size()-cnt<<endl;
    }
}

Submission (verdict: Accepted):
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
    int t;
    cin>>t;
    while(t--){
    int n,k;
    cin>>n>>k;
    map<ll,ll>m;
    for(int i=0;i<n;i++){
        ll x;
        cin>>x;
        m[x]++;
    }
    vector<int>v;
    for(auto& pr:m){
        v.push_back(pr.second);
    }
    sort(v.begin(),v.end());
    int sum=0,cnt=0;
    for(int i=0;i<v.size();i++){
    if(sum+v[i]<=k){ 
    sum+=v[i];
    cnt++;
    }
    }
    cout<<(v.size()>cnt ? v.size()-cnt:1)<<endl;
    }
}
Problem: 2057B - Gorilla and the Exam
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 1):
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
    int t;
    cin>>t;
    while(t--){
    int n,k;
    cin>>n>>k;
    map<ll,ll>m;
    for(int i=0;i<n;i++){
        ll x;
        cin>>x;
        m[x]++;
    }
     vector<int>v;
     for(auto pr:m){
         v.push_back(pr.second);
     }
     sort(v.begin(),v.end());
     int sum=0;
     for(int i=0;i<n;i++){
         sum+=v[i];
         if(sum>k){
             sum-=v[i];
             break;
         }
     }
     cout<<v.size()-sum<<endl;
    }
}

Submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
    int t;
    cin>>t;
    while(t--){
    int n,k;
    cin>>n>>k;
    map<ll,ll>m;
    for(int i=0;i<n;i++){
        ll x;
        cin>>x;
        m[x]++;
    }
     vector<int>v;
     for(auto pr:m){
         v.push_back(pr.second);
     }
     sort(v.begin(),v.end());
     int sum=0,cnt=0;
     for(int i=0;i<n;i++){
         sum+=v[i];
         cnt++;
         if(sum>k||i==n-1){
            cnt--;
             break;
         }
     }
     cout<<v.size()-cnt<<endl;
    }
}
Problem: 2050E - Three Strings
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Wrong answer on test 1):
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <iterator>
#include <set>
#include <map>
#include <numeric>
#include <unordered_set>
#include <cstring> 
#include <bitset>
#include <climits>
#include <tuple>
#include <deque>
#include <queue>
using namespace std;
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<bool> vb;
 
#define PB push_back
#define F first
#define S second
const ll M = 1e9 + 7;

void solve() {
    string a, b, c;
    cin >> a >> b >> c; a = " " + a; b = " " + b; c = " " + c;
    int n = a.size(), m = b.size();
    vector<vector<ll> > dp(n + 1, vector<ll> (m + 1, 0));
    for (ll i = 0; i <= n; i++) {
        for (ll j = 0; j <= m; j++) {
            if (i == 0 && j == 0) {continue;}
            dp[i][j] = INT_MAX;
            if (i != 0) {
                if (c[i + j] == a[i]) {
                    dp[i][j] = dp[i - 1][j];
                }
                else {
                    dp[i][j] = dp[i - 1][j] + 1;
                }
            }
            if (j != 0) {
                if (c[i + j] == b[j]) {
                    dp[i][j] = min(dp[i][j], dp[i][j - 1]);
                }
                else {
                    dp[i][j] = min(dp[i][j], dp[i][j - 1] + 1);
                }
            }
            // cerr << dp[i][j] << " "; 
        } //cerr << "\n"; 
    }
    // cerr << "\n";
    cout << dp[n][m] << "\n";
}

 
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int t; 
    cin >> t;
    while(t--) {solve();}
    // solve();
    return 0;
}
Problem: 2060D - Subtract Min Sort
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
#define int long long
#define endl "\n"
#define fast ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(0);
using namespace std;
int32_t main() {
    fast;
    int t;
    cin >> t;
    while (t--) {
      int n ; cin >> n ;
       vector<int>v(n);
        for(int i=0 ; i < n ; i++) cin >> v[i] ;
         int cnt =1;
         bool f=0;
         for(int i=1 ; i < n ; i++){
            if(v[i] >= v[i-1]) cnt++;
            else if(i > 1 && v[i] < v[i-1] && cnt >=2 && abs(v[i-1]-v[i-2]) <= v[i] ) cnt=1 ;
            else {
                f=1;
                break;
            }
         }
         if(f) cout << "NO" <<endl;
         else cout << "YES" <<endl;


    }

    return 0;
}


Submission (verdict: Accepted):
#include <bits/stdc++.h>
#define int long long
#define endl "\n"
#define fast ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(0);
using namespace std;
int32_t main() {
    fast;
    int t;
    cin >> t;
    while (t--) {
      int n ; cin >> n ;
       vector<int>v(n);
        for(int i=0 ; i < n ; i++) cin >> v[i] ;
         int cnt =1;
         bool f=0;
         for(int i=1 ; i < n ; i++){
           int mn = min(v[i],v[i-1]);
           v[i]-=mn , v[i-1]-=mn ;
         }
         for(int i = 1; i < n ; i++){
            if(v[i] < v[i-1]){
                f =1 ;
                 break;
            }
         }
         if(f) cout << "NO" <<endl;
         else cout << "YES" <<endl;


    }

    return 0;
}
Problem: 2060D - Subtract Min Sort
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
#define int long long
#define endl "\n"
#define fast ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(0);
using namespace std;
int32_t main() {
    fast;
    int t;
    cin >> t;
    while (t--) {
      int n ; cin >> n ;
       vector<int>v(n);
        for(int i=0 ; i < n ; i++) cin >> v[i] ;
         int cnt =1;
         bool f=0;
         for(int i=1 ; i < n ; i++){
            if(v[i] >= v[i-1]) cnt++;
            else if(v[i] < v[i-1] && cnt >=2 ) cnt=1 ;
            else {
                f=1;
                break;
            }
         }
         if(f) cout << "NO" <<endl;
         else cout << "YES" <<endl;


    }

    return 0;
}


Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
#define int long long
#define endl "\n"
#define fast ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(0);
using namespace std;
int32_t main() {
    fast;
    int t;
    cin >> t;
    while (t--) {
      int n ; cin >> n ;
       vector<int>v(n);
        for(int i=0 ; i < n ; i++) cin >> v[i] ;
         int cnt =1;
         bool f=0;
         for(int i=1 ; i < n ; i++){
            if(v[i] >= v[i-1]) cnt++;
            else if(i > 1 && v[i] < v[i-1] && cnt >=2 && abs(v[i-1]-v[i-2]) <= v[i] ) cnt=1 ;
            else {
                f=1;
                break;
            }
         }
         if(f) cout << "NO" <<endl;
         else cout << "YES" <<endl;


    }

    return 0;
}
Problem: 2060D - Subtract Min Sort
Language: C++20 (GCC 13-64)


Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
#define int long long
#define endl "\n"
#define fast ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(0);
using namespace std;
int32_t main() {
    fast;
    int t;
    cin >> t;
    while (t--) {
      int n ; cin >> n ;
       vector<int>v(n);
        for(int i=0 ; i < n ; i++) cin >> v[i] ;
         int cnt =1;
         bool f=0;
         for(int i=1 ; i < n ; i++){
            if(v[i] > v[i-1]) cnt++;
            else if(v[i] < v[i-1] && cnt >=2 ) cnt=1 ;
            else {
                f=1;
                break;
            }
         }
         if(f) cout << "NO" <<endl;
         else cout << "YES" <<endl;


    }

    return 0;
}
Problem: 2060D - Subtract Min Sort
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
#define int long long
#define endl "\n"
#define fast ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(0);
using namespace std;
int32_t main() {
    fast;
    int t;
    cin >> t;
    while (t--) {
      int n ; cin >> n ;
       vector<int>v(n);
        for(int i=0 ; i < n ; i++) cin >> v[i] ;
         int cnt =1;
         bool f=0;
         for(int i=1 ; i < n ; i++){
            if(v[i] > v[i-1]) cnt++;
            else if(v[i] < v[i-1] && cnt >=2 ) cnt=1 ;
            else {
                f=1;
                break;
            }
         }
         if(f) cout << "NO" <<endl;
         else cout << "YES" <<endl;


    }

    return 0;
}


Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
#define int long long
#define endl "\n"
#define fast ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(0);
using namespace std;
int32_t main() {
    fast;
    int t;
    cin >> t;
    while (t--) {
      int n ; cin >> n ;
       vector<int>v(n);
        for(int i=0 ; i < n ; i++) cin >> v[i] ;
         int cnt =1;
         bool f=0;
         for(int i=1 ; i < n ; i++){
            if(v[i] >= v[i-1]) cnt++;
            else if(v[i] < v[i-1] && cnt >=2 ) cnt=1 ;
            else {
                f=1;
                break;
            }
         }
         if(f) cout << "NO" <<endl;
         else cout << "YES" <<endl;


    }

    return 0;
}
Problem: 2061D - Kevin and Numbers
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
#define ll long long
#define mod 998244353
using namespace std;
map<int,int>mp;
bool rec(int i){
    if(mp[i]) {
            mp[i]--;
            if(mp[i]==0)  mp.erase(i);
            return 1;
    }
    if((mp.begin()->first)<i) return 0;
    return rec((i+1)/2)&rec(i/2);

}
int main()
{
  //freopen("input.txt","r",stdin);
  //freopen("out.txt","w",stdout);
   ios_base::sync_with_stdio(false);
   cin.tie(nullptr), cout.tie(nullptr);
   ll t,n,m; cin>>t;
   string s;
   while(t--){
     cin>>n>>m;
     ll sum1=0,sum2=0;
     vector<ll>a(n),b(m);
     for(auto&it:a) cin>>it,mp[it]++,sum1+=it;
     for(auto&it:b) cin>>it,sum2+=it;
     bool f=1;
     if(sum1!=sum2){
        cout<<"NO\n";
        continue;
     }
     sort(b.begin(),b.end());
     for(int i=0;i<m;i++){
        f&=rec(b[i]);
        if(!f) break;
     }
     if(f) cout<<"YES\n"; else cout<<"NO\n";
     mp.clear();
   }
    return 0;
}


Submission (verdict: Accepted):
#include <bits/stdc++.h>
#define ll long long
#define mod 998244353
using namespace std;
map<int,int>mp;
ll ct,n,m;
bool rec(int i){
    if(mp.begin()->first>i)
        return 0;
    if(mp[i]) {
        mp[i]--;
        if(mp[i]==0)
            mp.erase(i);
        return 1;
    }
    ct++;
    if(ct>n-m) return 0;
    return rec((i+1)/2)&rec(i/2);

}
int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
    ll t; cin>>t;
    string s;
    while(t--){
        ct=0;
        cin>>n>>m;
        ll sum1=0,sum2=0;
        vector<int>a(n),b(m);
        for(auto&it:a) cin>>it,mp[it]++,sum1+=it;
        for(auto&it:b) cin>>it,sum2+=it;
        bool f=1;
        if(sum1!=sum2){
            mp.clear();
            cout<<"NO\n";
            continue;
        }
        sort(b.begin(),b.end());
        for(int i=0;i<m;i++){
            f&=rec(b[i]);
            if(ct>n-m) f=0;
            if(!f) break;
        }
        if(f) cout<<"YES\n"; else cout<<"NO\n";
        mp.clear();
    }
    return 0;
}
Problem: 2061D - Kevin and Numbers
Language: C++20 (GCC 13-64)


Submission (verdict: Time limit exceeded on test 27):
#include <bits/stdc++.h>
#define ll long long
#define mod 998244353
using namespace std;
unordered_map<int,int>mp;
ll mi=0;
bool rec(int i){
    if(mp[i]) {
            mp[i]--;
            return 1;
    }
    if(i<=mi) return 0;
    return rec((i+1)/2)&rec(i/2);

}
int main()
{
  //freopen("input.txt","r",stdin);
  //freopen("out.txt","w",stdout);
   ios_base::sync_with_stdio(false);
   cin.tie(nullptr), cout.tie(nullptr);
   ll t,n,m; cin>>t;
   string s;
   while(t--){
     cin>>n>>m;
     ll sum1=0,sum2=0;
     vector<ll>a(n),b(m);
     mi=1e9;
     for(auto&it:a) cin>>it,mp[it]++,sum1+=it,mi=min(mi,it);
     for(auto&it:b) cin>>it,sum2+=it;
     bool f=1;
     if(sum1!=sum2){
        cout<<"NO\n";
        continue;
     }
     sort(b.begin(),b.end());
     for(int i=0;i<m;i++){
        f&=rec(b[i]);
        if(!f) break;
     }
     if(f) cout<<"YES\n"; else cout<<"NO\n";
     mp.clear();
   }
    return 0;
}