ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2052A - Adrenaline Rush
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 1):
#include<bits/stdc++.h>
using namespace std;
#define all(x) x.begin(), x.end()
#define int long long
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int a,b,d,k;;
    cin>>b;
    vector<int> v;for(int i=0;i<b;i++){cin>>d;v.insert(v.end(),d);}
    vector<int> c;
    vector<bool> n(b);
    vector<array<int,2>> g;
    for(int i=0;i<b;i++){
        c.insert(c.end(),i);
    }
    for(int i=0;i<b;i++){
        n[v[i]]=1;
        for(int j=v[i];j<b;j++){
            if(n[j]!=1){
                g.insert(g.end(),{j,v[i]});
            }
        }
        for(int j=b;j>=0;j--){
            if(n[j]!=1){
                g.insert(g.end(),{v[i],j});
            }
        } 
    }
    cout<<g.size()<<endl;
    for(auto [x,y]:g){
        cout<<x<<' '<<y<<endl;
    }
    v.erase(all(v));
    c.erase(all(c));
    n.erase(all(n));
    g.erase(all(g));
    }

Submission (verdict: Accepted):
#include<bits/stdc++.h>
using namespace std;
#define all(x) x.begin(), x.end()
#define int long long
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int a,b,d,k;;
    cin>>b;
    vector<int> v;for(int i=0;i<b;i++){cin>>d;v.insert(v.end(),d);}
    vector<int> c;
    vector<bool> n(b);
    vector<array<int,2>> g;
    for(int i=0;i<b;i++){
        c.insert(c.end(),i);
    }
    for(int i=0;i<b;i++){
        n[v[i]]=1;
        for(int j=v[i];j<=b;j++){
            if(n[j]!=1){
                g.insert(g.end(),{j,v[i]});
            }
        }
        for(int j=b;j>=1;j--){
            if(n[j]!=1){
                g.insert(g.end(),{v[i],j});
            }
        } 
    }
    cout<<g.size()<<endl;
    for(auto [x,y]:g){
        cout<<x<<' '<<y<<endl;
    }
    v.erase(all(v));
    c.erase(all(c));
    n.erase(all(n));
    g.erase(all(g));
    }
Problem: 2052A - Adrenaline Rush
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Runtime error on test 1):
#include<bits/stdc++.h>
using namespace std;
#define all(x) x.begin(), x.end()
#define int long long
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin.tie(nullptr);
    int a,b,d,k;cin>>a;
    cin>>b;
    vector<int> v;for(int i=0;i<b;i++){cin>>d;v.insert(v.end(),d);}
    vector<int> c;
    vector<bool> n;
    vector<array<int,2>> g;
    for(int i=0;i<b;i++){
        c.insert(c.end(),i);
    }
    for(int i=0;i<b;i++){
        n[v[i]]=1;
        for(int j=v[i];j<b;j++){
            if(n[j]!=1){
                g.insert(g.end(),{j,v[i]});
            }
        }
        for(int j=b;j>=1;j--){
            if(n[j]!=1){
                g.insert(g.end(),{v[i],j});
            }
        } 
    }
    cout<<g.size()<<endl;
    for(auto [x,y]:g){
        cout<<x<<' '<<y<<endl;
    }
    v.erase(all(v));
    c.erase(all(c));
    n.erase(all(n));
    g.erase(all(g));
    }
Problem: 2052A - Adrenaline Rush
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Runtime error on test 1):
#include<bits/stdc++.h>
using namespace std;
#define all(x) x.begin(), x.end()
#define int long long
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin.tie(nullptr);
    int a,b,d,k;cin>>a;
    cin>>b;
    vector<int> v;for(int i=0;i<b;i++){cin>>d;v.insert(v.end(),d);}
    vector<int> c;
    vector<bool> n;
    vector<array<int,2>> g;
    for(int i=0;i<b;i++){
        c.insert(c.end(),i);
    }
    for(int i=0;i<b;i++){
        n[v[i]]=1;
        for(int j=v[i];j<b;j++){
            if(n[j]!=1){
                g.insert(g.end(),{j,v[i]});
            }
        }
        for(int j=b;j>=1;j--){
            if(n[j]!=1){
                g.insert(g.end(),{v[i],j});
            }
        } 
    }
    cout<<g.size()<<endl;
    for(auto [x,y]:g){
        cout<<x<<' '<<y<<endl;
    }
    v.erase(all(v));
    c.erase(all(c));
    n.erase(all(n));
    g.erase(all(g));
    }

Submission (verdict: Runtime error on test 1):
#include<bits/stdc++.h>
using namespace std;
#define all(x) x.begin(), x.end()
#define int long long
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin.tie(nullptr);
    int a,b,d,k;cin>>a;
    cin>>b;
    vector<int> v;for(int i=0;i<b;i++){cin>>d;v.insert(v.end(),d);}
    vector<int> c;
    vector<bool> n;
    vector<array<int,2>> g;
    for(int i=0;i<b;i++){
        c.insert(c.end(),i);
    }
    for(int i=0;i<b;i++){
        n[v[i]]=1;
        for(int j=v[i];j<b;j++){
            if(n[j]!=1){
                g.insert(g.end(),{j,v[i]});
            }
        }
        for(int j=b;j>=1;j--){
            if(n[j]!=1){
                g.insert(g.end(),{v[i],j});
            }
        } 
    }
    cout<<g.size()<<endl;
    for(auto [x,y]:g){
        cout<<x<<' '<<y<<endl;
    }
    // v.erase(all(v));
    // c.erase(all(c));
    // n.erase(all(n));
    // g.erase(all(g));
    }
Problem: 2052A - Adrenaline Rush
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Runtime error on test 1):
#include<bits/stdc++.h>
using namespace std;
#define all(x) x.begin(), x.end()
#define int long long
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin.tie(nullptr);
    int a,b,d,k;cin>>a;
    cin>>b;
    vector<int> v;for(int i=0;i<b;i++){cin>>d;v.insert(v.end(),d);}
    vector<int> c;
    vector<bool> n;
    vector<array<int,2>> g;
    for(int i=0;i<b;i++){
        c.insert(c.end(),i);
    }
    for(int i=0;i<b;i++){
        n[v[i]]=1;
        for(int j=v[i];j<b;j++){
            if(n[j]!=1){
                g.insert(g.end(),{j,v[i]});
            }
        }
        for(int j=b;j>=1;j--){
            if(n[j]!=1){
                g.insert(g.end(),{v[i],j});
            }
        } 
    }
    cout<<g.size()<<endl;
    for(auto [x,y]:g){
        cout<<x<<' '<<y<<endl;
    }
    // v.erase(all(v));
    // c.erase(all(c));
    // n.erase(all(n));
    // g.erase(all(g));
    }

Submission (verdict: Wrong answer on test 1):
#include<bits/stdc++.h>
using namespace std;
#define all(x) x.begin(), x.end()
#define int long long
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int a,b,d,k;;
    cin>>b;
    vector<int> v;for(int i=0;i<b;i++){cin>>d;v.insert(v.end(),d);}
    vector<int> c;
    vector<bool> n(b);
    vector<array<int,2>> g;
    for(int i=0;i<b;i++){
        c.insert(c.end(),i);
    }
    for(int i=0;i<b;i++){
        n[v[i]]=1;
        for(int j=v[i];j<b;j++){
            if(n[j]!=1){
                g.insert(g.end(),{j,v[i]});
            }
        }
        for(int j=b;j>=1;j--){
            if(n[j]!=1){
                g.insert(g.end(),{v[i],j});
            }
        } 
    }
    cout<<g.size()<<endl;
    for(auto [x,y]:g){
        cout<<x<<' '<<y<<endl;
    }
    v.erase(all(v));
    c.erase(all(c));
    n.erase(all(n));
    g.erase(all(g));
    }
Problem: 2052A - Adrenaline Rush
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 1):
#include<bits/stdc++.h>
using namespace std;
#define all(x) x.begin(), x.end()
#define int long long
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int a,b,d,k;;
    cin>>b;
    vector<int> v;for(int i=0;i<b;i++){cin>>d;v.insert(v.end(),d);}
    vector<int> c;
    vector<bool> n(b);
    vector<array<int,2>> g;
    for(int i=0;i<b;i++){
        c.insert(c.end(),i);
    }
    for(int i=0;i<b;i++){
        n[v[i]]=1;
        for(int j=v[i];j<b;j++){
            if(n[j]!=1){
                g.insert(g.end(),{j,v[i]});
            }
        }
        for(int j=b;j>=1;j--){
            if(n[j]!=1){
                g.insert(g.end(),{v[i],j});
            }
        } 
    }
    cout<<g.size()<<endl;
    for(auto [x,y]:g){
        cout<<x<<' '<<y<<endl;
    }
    v.erase(all(v));
    c.erase(all(c));
    n.erase(all(n));
    g.erase(all(g));
    }

Submission (verdict: Wrong answer on test 1):
#include<bits/stdc++.h>
using namespace std;
#define all(x) x.begin(), x.end()
#define int long long
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int a,b,d,k;;
    cin>>b;
    vector<int> v;for(int i=0;i<b;i++){cin>>d;v.insert(v.end(),d);}
    vector<int> c;
    vector<bool> n(b);
    vector<array<int,2>> g;
    for(int i=0;i<b;i++){
        c.insert(c.end(),i);
    }
    for(int i=0;i<b;i++){
        n[v[i]]=1;
        for(int j=v[i];j<b;j++){
            if(n[j]!=1){
                g.insert(g.end(),{j,v[i]});
            }
        }
        for(int j=b;j>=0;j--){
            if(n[j]!=1){
                g.insert(g.end(),{v[i],j});
            }
        } 
    }
    cout<<g.size()<<endl;
    for(auto [x,y]:g){
        cout<<x<<' '<<y<<endl;
    }
    v.erase(all(v));
    c.erase(all(c));
    n.erase(all(n));
    g.erase(all(g));
    }
Problem: 2061D - Kevin and Numbers
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 3):
#include<bits/stdc++.h>
#define int long long
using namespace std;
priority_queue<int,vector<int>,greater<int> >a,b;
map<int,int> ma;
int n,m;
bool cal(int x)
{
if(x==0)return 0;
if(ma[x]>0)
{
	ma[x]--;
	n--;
	return 1;
}
return cal(x/2)&&cal(x/2+x%2);
}
void solve()
{

	cin>>n>>m;
	ma.clear();
	for(int i=1;i<=n;i++)
	{
		int temp;cin>>temp;
		ma[temp]++;
	}
	for(int i=1;i<=m;i++)
	{
		int temp;cin>>temp;
		if(cal(temp)==0)
		{
			cout<<"NO\n";
			return ;
		}
	}
	if(n==0)
	cout<<"YES\n";
else cout<<"NO\n";
	return;
}
signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int T;
	cin>>T;
	while(T--)
	solve();
}
Problem: 2061D - Kevin and Numbers
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 3):
#include<bits/stdc++.h>
#define int long long
using namespace std;
map<int,int> ma;
int n,m;
bool cal(int x)
{
if(ma[x]>0)
{
	ma[x]--;
	n--;
	return 1;
}
if(x==1)
	return 0;
return cal(x/2)&&cal(x/2+x%2);
}
void solve()
{

	cin>>n>>m;
	ma.clear();
	for(int i=1;i<=n;i++)
	{
		int temp;cin>>temp;
		ma[temp]++;
	}
	for(int i=1;i<=m;i++)
	{
		int temp;cin>>temp;
		if(cal(temp)==0)
		{
			cout<<"NO\n";
			return ;
		}
	}
	if(n==0)
	cout<<"YES\n";
else cout<<"NO\n";
	return;
}
signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int T;
	cin>>T;
	while(T--)
	solve();
}

Submission (verdict: Wrong answer on test 1):
#include<bits/stdc++.h>
#define int long long
using namespace std;
map<int,int> ma;
int n,m;
bool cal(int x)
{
if(ma[x]>0)
{
	ma[x]--;
	n--;
	return 1;
}
if(x==1)
	return 0;
return cal(x/2)&&cal(x/2+x%2);
}
void solve()
{

	cin>>n>>m;
	ma.clear();
	for(int i=1;i<=n;i++)
	{
		int temp;cin>>temp;
		ma[temp]++;
	}
	for(int i=1;i<=m;i++)
	{
		int temp;cin>>temp;
		if(cal(temp)==0)
		{
			cout<<"NO\n";
			for(int j=i+1;i<=n;i++)
				cin>>temp;
			return ;
		}
	}
	if(n==0)
	cout<<"YES\n";
else cout<<"NO\n";
	return;
}
signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int T;
	cin>>T;
	while(T--)
	solve();
}
Problem: 2061D - Kevin and Numbers
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 1):
#include<bits/stdc++.h>
#define int long long
using namespace std;
map<int,int> ma;
int n,m;
bool cal(int x)
{
if(ma[x]>0)
{
	ma[x]--;
	n--;
	return 1;
}
if(x==1)
	return 0;
return cal(x/2)&&cal(x/2+x%2);
}
void solve()
{

	cin>>n>>m;
	ma.clear();
	for(int i=1;i<=n;i++)
	{
		int temp;cin>>temp;
		ma[temp]++;
	}
	for(int i=1;i<=m;i++)
	{
		int temp;cin>>temp;
		if(cal(temp)==0)
		{
			cout<<"NO\n";
			for(int j=i+1;i<=n;i++)
				cin>>temp;
			return ;
		}
	}
	if(n==0)
	cout<<"YES\n";
else cout<<"NO\n";
	return;
}
signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int T;
	cin>>T;
	while(T--)
	solve();
}

Submission (verdict: Accepted):
#include<bits/stdc++.h>
#define int long long
using namespace std;
map<int,int> ma;
int n,m;
bool cal(int x)
{
if(ma[x]>0)
{
	ma[x]--;
	n--;
	return 1;
}
if(x==1)
	return 0;
return cal(x/2)&&cal(x/2+x%2);
}
void solve()
{

	cin>>n>>m;
	ma.clear();
	for(int i=1;i<=n;i++)
	{
		int temp;cin>>temp;
		ma[temp]++;
	}
	for(int i=1;i<=m;i++)
	{
		int temp;cin>>temp;
		if(cal(temp)==0)
		{
			cout<<"NO\n";
			for(int j=i+1;j<=m;j++)
				cin>>temp;
			return ;
		}
	}
	if(n==0)
	cout<<"YES\n";
else cout<<"NO\n";
	return;
}
signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int T;
	cin>>T;
	while(T--)
	solve();
}
Problem: 2061D - Kevin and Numbers
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 3):
#include<bits/stdc++.h>
#define int long long
using namespace std;
priority_queue<int,vector<int>,greater<int> >a,b;
map<int,int> ma;
int n,m;
bool cal(int x)
{
if(x==0)return 0;
if(ma[x]>0)
{
	ma[x]--;
	n--;
	return 1;
}
return cal(x/2)&&cal(x/2+x%2);
}
void solve()
{

	cin>>n>>m;
	ma.clear();
	for(int i=1;i<=n;i++)
	{
		int temp;cin>>temp;
		ma[temp]++;
	}
	for(int i=1;i<=m;i++)
	{
		int temp;cin>>temp;
		if(cal(temp)==0)
		{
			cout<<"NO\n";
			return ;
		}
	}
	if(n==0)
	cout<<"YES\n";
else cout<<"NO\n";
	return;
}
signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int T;
	cin>>T;
	while(T--)
	solve();
}

Submission (verdict: Wrong answer on test 3):
#include<bits/stdc++.h>
#define int long long
using namespace std;
map<int,int> ma;
int n,m;
bool cal(int x)
{
if(ma[x]>0)
{
	ma[x]--;
	n--;
	return 1;
}
if(x==1)
	return 0;
return cal(x/2)&&cal(x/2+x%2);
}
void solve()
{

	cin>>n>>m;
	ma.clear();
	for(int i=1;i<=n;i++)
	{
		int temp;cin>>temp;
		ma[temp]++;
	}
	for(int i=1;i<=m;i++)
	{
		int temp;cin>>temp;
		if(cal(temp)==0)
		{
			cout<<"NO\n";
			return ;
		}
	}
	if(n==0)
	cout<<"YES\n";
else cout<<"NO\n";
	return;
}
signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int T;
	cin>>T;
	while(T--)
	solve();
}
Problem: 2063C - Remove Exactly Two
Language: C++17 (GCC 7-32)


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

#define fi first
#define se second
#define gcd __gcd
#define sz(v) (int) v.size()
#define pb push_back
#define pi pair<int,int>
#define all(v) (v).begin(), (v).end()
#define compact(v) (v).erase(unique(all(v)), (v).end())
#define FOR(i, a, b) for(int i = (a); i <= (b); i++)
#define REV(i, a, b) for(int i = (a); i >= (b); i--)
#define dbg(x) "[" #x " = " << (x) << "]"
///#define int long long

using ll = long long;
using ld = long double;
using ull = unsigned long long;

template<typename T> bool ckmx(T& a, const T& b){if(a < b) return a = b, true; return false;}
template<typename T> bool ckmn(T& a, const T& b){if(a > b) return a = b, true; return false;}

const int N = 2e5+5;
const ll MOD = 1e9+7;
const ll INF = 1e18;




void solve()
{
    int n; cin >> n;

    vector<vector<int>> adj(n + 1, vector<int>());
    FOR(i, 1, n - 1){
        int u,v; cin >> u >> v;
        adj[u].pb(v), adj[v].pb(u);
    }

    vector<int> f(n + 1, -1e9);

    int answer = 0;

    auto dfs = [&](auto&& dfs, int x, int p) -> void{
        for(int v : adj[x])if(v != p){
            dfs(dfs, v, x);

            f[x] = max(f[x], max(sz(adj[v]) - 1, f[v]));
            answer = max(answer, sz(adj[x]) + sz(adj[v]) - 2);
            answer = max(answer, sz(adj[x]) + f[v]);
        }
    };

    dfs(dfs, 1, -1);

    cout << answer << "\n";
}

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    #define name "InvMOD"
    if(fopen(name".INP", "r")){
        freopen(name".INP","r",stdin);
        freopen(name".OUT","w",stdout);
    }

    int t = 1; cin >> t;
    while(t--) solve();
    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>
using namespace std;
#define nl '\n'
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long int
ll mod = 1e+7;
vector<ll> a, b;
unordered_multiset<ll> myset;
bool nosol = false;
ll n,m;
ll countt=0;

void rec(ll num){
    if(nosol){
        return;
    }
    auto it = myset.find(num);
    if(it!=myset.end()){
        myset.erase(it);
    }else{
        countt++;
        ll num1= floor(num/2);
        ll num2= ceil(double(num)/2);
        if(num1==0 || num2==0 || countt > n-m){
            nosol= true;
        }
        rec(num1);
        rec(num2);
    }
}

int main(){
    IOS
    ll t;
    cin>>t;
    while(t--){
        countt=0;
        myset.clear();
        a.clear(), b.clear();
        nosol= false;
        cin>>n>>m;
        a.resize(n);
        b.resize(m);

        ll suma=0;
        ll sumb=0;
        for(ll i=0; i<n; i++){
            cin>>a[i];
            myset.insert(a[i]);
            suma+=a[i];
        }
        for(ll i=0; i<m; i++){
            cin>>b[i];
            sumb+=b[i];
        }

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

        for(ll i=0; i<m; i++){
            rec(b[i]);
        }
        if(!nosol && countt==n-m){
            cout<<"YES"<<'\n';
        }else{
            cout<<"NO"<<'\n';
        }


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

Previous submission (verdict: Time limit exceeded on test 27):
#include <bits/stdc++.h>
using namespace std;
#define nl '\n'
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long int
ll mod = 1e+7;
vector<ll> a, b;
unordered_multiset<ll> myset;
bool nosol = false;
ll n,m;
ll countt=0;

void rec(ll num){
    if(nosol){
        return;
    }
    auto it = myset.find(num);
    if(it!=myset.end()){
        myset.erase(it);
    }else{
        countt++;
        ll num1= floor(num/2);
        ll num2= ceil(double(num)/2);
        if(num1==0 || num2==0 || countt > n-m){
            nosol= true;
        }
        rec(num1);
        rec(num2);
    }
}

int main(){
    IOS
    ll t;
    cin>>t;
    while(t--){
        countt=0;
        myset.clear();
        a.clear(), b.clear();
        nosol= false;
        cin>>n>>m;
        a.resize(n);
        b.resize(m);

        ll suma=0;
        ll sumb=0;
        for(ll i=0; i<n; i++){
            cin>>a[i];
            myset.insert(a[i]);
            suma+=a[i];
        }
        for(ll i=0; i<m; i++){
            cin>>b[i];
            sumb+=b[i];
        }

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

        for(ll i=0; i<m; i++){
            rec(b[i]);
        }
        if(!nosol && countt==n-m){
            cout<<"YES"<<'\n';
        }else{
            cout<<"NO"<<'\n';
        }


    }
    return 0;
}

Submission (verdict: Memory limit exceeded on test 6):
#include <bits/stdc++.h>
using namespace std;
#define nl '\n'
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long int

int main() {
    IOS
    ll t;
    cin >> t;
    while (t--) {
        ll n, m;
        cin >> n >> m;

        vector<ll> a(n), b(m);
        multiset<ll> myset;

        ll suma = 0, sumb = 0;
        for (ll i = 0; i < n; i++) {
            cin >> a[i];
            suma += a[i];
            myset.insert(a[i]);
        }

        for (ll i = 0; i < m; i++) {
            cin >> b[i];
            sumb += b[i];
        }

        if (suma != sumb) {
            cout << "NO" << nl;
            continue;
        }

        priority_queue<ll> pq;
        for (ll num : b) pq.push(num);

        bool possible = true;
        while (!pq.empty()) {
            ll top = pq.top();
            pq.pop();

            auto it = myset.find(top);
            if (it != myset.end()) {
                myset.erase(it); 
            } else {
                if (top == 1) { 
                    possible = false;
                    break;
                }
                pq.push(top / 2);
                pq.push((top + 1) / 2);
            }
        }

        if (possible && myset.empty()) {
            cout << "YES" << nl;
        } else {
            cout << "NO" << nl;
        }
    }
    return 0;
}
Problem: 2061D - Kevin and Numbers
Language: C++20 (GCC 13-64)

Previous submission (verdict: Memory limit exceeded on test 6):
#include <bits/stdc++.h>
using namespace std;
#define nl '\n'
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long int

int main() {
    IOS
    ll t;
    cin >> t;
    while (t--) {
        ll n, m;
        cin >> n >> m;

        vector<ll> a(n), b(m);
        multiset<ll> myset;

        ll suma = 0, sumb = 0;
        for (ll i = 0; i < n; i++) {
            cin >> a[i];
            suma += a[i];
            myset.insert(a[i]);
        }

        for (ll i = 0; i < m; i++) {
            cin >> b[i];
            sumb += b[i];
        }

        if (suma != sumb) {
            cout << "NO" << nl;
            continue;
        }

        priority_queue<ll> pq;
        for (ll num : b) pq.push(num);

        bool possible = true;
        while (!pq.empty()) {
            ll top = pq.top();
            pq.pop();

            auto it = myset.find(top);
            if (it != myset.end()) {
                myset.erase(it); 
            } else {
                if (top == 1) { 
                    possible = false;
                    break;
                }
                pq.push(top / 2);
                pq.push((top + 1) / 2);
            }
        }

        if (possible && myset.empty()) {
            cout << "YES" << nl;
        } else {
            cout << "NO" << nl;
        }
    }
    return 0;
}


Submission (verdict: Time limit exceeded on test 5):
#include <bits/stdc++.h>
using namespace std;
#define nl '\n'
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long int

int main() {
    IOS
    ll t;
    cin >> t;
    while (t--) {
        ll n, m;
        cin >> n >> m;

        vector<ll> a(n), b(m);
        multiset<ll> myset;

        ll suma = 0, sumb = 0;
        for (ll i = 0; i < n; i++) {
            cin >> a[i];
            suma += a[i];
            myset.insert(a[i]);
        }

        for (ll i = 0; i < m; i++) {
            cin >> b[i];
            sumb += b[i];
        }

        if (suma != sumb) {
            cout << "NO" << nl;
            continue;
        }


        multiset<ll> splitSet(b.begin(), b.end());

        bool possible = true;
        while (!splitSet.empty()) {
            ll largest = *splitSet.rbegin();
            splitSet.erase(prev(splitSet.end()));

            auto it = myset.find(largest);
            if (it != myset.end()) {
                myset.erase(it);
            } else {

                if (largest == 1) {
                    possible = false;
                    break;
                }


                splitSet.insert(largest / 2);
                splitSet.insert((largest + 1) / 2);
            }
        }

        if (possible && myset.empty()) {
            cout << "YES" << nl;
        } else {
            cout << "NO" << nl;
        }
    }
    return 0;
}