ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2060D - Subtract Min Sort
Language: c++17 

Code 1:
#include <bits/stdc++.h>
using namespace std;
void solve(){
    int n;
        cin >>n;
        int a[n];
        for(int i=0; i<n; i++){
            cin >> a[i];
        }
        for(int i=0; i<n-1; i++){
            if(a[i]>a[i+1]){
                cout << "NO\n";
                return;
            }else{
                a[i+1]-=min(a[i],a[i+1]);
                a[i]-=min(a[i],a[i+1]);
            }
        }
        cout << "YES\n";
}
int main(){
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    int t;
    cin >> t;
    while(t--){
        solve();}
        return 0;
}

Code 2:
#include <bits/stdc++.h>
using namespace std;
void solve(){
    int n;
        cin >>n;
        int a[n];
        for(int i=0; i<n; i++){
            cin >> a[i];
        }
        for(int i=0; i<n-1; i++){
            if(a[i]>a[i+1]){
                cout << "NO\n";
                return;
            }else{
                a[i+1]-=min(a[i],a[i+1]);
                a[i]-=min(a[i],a[i+1]);
            }
        }
        cout << "YES\n";
}
int main(){
    int t;
    cin >> t;
    while(t--){
        solve();}
        return 0;
}

Answer: 2
Problem: 2060D - Subtract Min Sort
Language: c++20 

Code 1:
#include<bits/stdc++.h>
using namespace std;
#define int long long 
const int N=2e5+10;
int a[N];
int n;
void solve(){
	a[0]=0;
	for(int i=1;i<n;i++){
		int x=min(a[i],a[i+1]);
		a[i]-=x;
		a[i+1]-=x;
		if(a[i]<a[i-1]){
			cout<<"NO"<<endl;
			return ;
		}
	}
	cout<<"YES"<<endl;
}
signed main(){
	int t;
	cin>>t;
	while(t--){
		cin>>n;
		for(int i=1;i<=n;i++){
			cin>>a[i];
		}
		solve();
	}
	
}

Code 2:
#include<bits/stdc++.h>
using namespace std;
#define int long long 
const int N=2e5+10;
int a[N];
int n;
void solve(){
	a[0]=0;
	for(int i=1;i<n;i++){
		int x=min(a[i],a[i+1]);
		a[i]-=x;
		a[i+1]-=x;
		if(a[i]<a[i-1]){
			cout<<"NO"<<endl;
			return ;
		}
	}
	for(int i=1;i<n;i++){
		if(a[i]>a[i+1]){
			cout<<"NO"<<endl;
			return ;
		}
	}
	cout<<"YES"<<endl;
}
signed main(){
	int t;
	cin>>t;
	while(t--){
		cin>>n;
		for(int i=1;i<=n;i++){
			cin>>a[i];
		}
		solve();
	}
	
}

Answer: 2
Problem: 2060D - Subtract Min Sort
Language: c++23 

Code 1:
#include <iostream>

#include <vector>

using namespace std;



void solve()

{

    int n;

    cin >> n;

    vector<int> a(n);



    for (int i = 0; i < n; i++) 

    {

        cin >> a[i];

    }



    for (int i = 0; i < n - 1; i++) 

    {

        if (a[i] > a[i + 1]) 

        {

            int diff = a[i] - a[i + 1];

            a[i] -= diff;  // Reduce both a[i] and a[i+1] by 'diff'

            a[i + 1] -= diff;

        }

        if (a[i] > a[i + 1]) 

        {

            cout << "NO" << endl;

            return;

        }

    }



    cout << "YES" << endl;

}



int main()

{

    int t;

    cin >> t;



    while (t--) 

    {

        solve();

    }



    return 0;

}



Code 2:
#include <bits/stdc++.h>

using namespace std;

using ll = long long;



void solve() {

    ll n;

    cin >> n;

    vector<ll> a(n);

    

    for (ll &x : a) cin >> x;



    ll last = 0;

    

    // Find the last position where a[i] > a[i+1]

    for (ll i = 1; i < n; i++) {

        if (a[i - 1] > a[i]) last = i;

    }



    // If already sorted, return YES

    if (last == 0) {

        cout << "YES\n";

        return;

    }



    // Apply the operation

    for (ll i = 0; i < last; i++) {

        ll min_val = min(a[i], a[i + 1]);

        a[i] -= min_val;

        a[i + 1] -= min_val;

    }



    // Check if sorted after operations

    cout << (is_sorted(a.begin(), a.end()) ? "YES" : "NO") << '\n';

}



int main() {

    ios::sync_with_stdio(false);

    cin.tie(nullptr);

    

    ll t;

    cin >> t;

    while (t--) solve();

    

    return 0;

}



Answer: 2
Problem: 2060D - Subtract Min Sort
Language: c++17 

Code 1:
#include <bits/stdc++.h>
using namespace std;
#define int long long int

int sum(vector<int> &a, int n)
{
    int x = 0;
    for (int i = 0; i < n; i++)
    {
        x += abs(a[i]);
    }
    return x;
}

void solve()
{
   int n; cin>>n;
   vector<int>a(n);
   for(int &x : a) cin>>x;
   int g = 0, f = 0;
   for(int i=1;i<n;i++){
    if(a[i] == a[i-1]) continue;
    if(a[i] < a[i-1] && !g) f = 1;
    if(a[i] > a[i-1]) g = 1;
   }
   if(f==0) cout<<"YES\n";
   else cout<<"NO\n";
}

int32_t main()
{
    int t;
    cin >> t;
    while (t--)
    {
        solve();
    }
}


Code 2:
#include <bits/stdc++.h>
using namespace std;
#define int long long int

int sum(vector<int> &a, int n)
{
    int x = 0;
    for (int i = 0; i < n; i++)
    {
        x += abs(a[i]);
    }
    return x;
}

void solve()
{
   int n; cin>>n;
   vector<int>a(n);
   for(int &x : a) cin>>x;
   int g = 0, f = 0;
   for(int i=1;i<n;i++){
        int x = min(a[i],a[i-1]);
        a[i] -= x;
        a[i-1] -= x;
        if(0 == a[i] && a[i-1] != 0) {f = 1; break;}
   }
   if(f==0) cout<<"YES\n";
   else cout<<"NO\n";
}

int32_t main()
{
    int t;
    cin >> t;
    while (t--)
    {
        solve();
    }
}


Answer: 2
Problem: 2060D - Subtract Min Sort
Language: c++17 

Code 1:
#include<bits/stdc++.h>

using namespace std;

void opp(int &i,int &j){

int k=min(i,j);

i-=k;

j-=k;

}

int can3be(vector<int> &v,int i){

int i1=v[i],j1=v[i+1],k1=v[i+2];

int i2=v[i],j2=v[i+1],k2=v[i+2];

opp(i1,j1);opp(j1,k1);

opp(j2,k2);opp(i2,j2);

if(i1<=j1&&j1<=k1){

opp(v[i],v[i+1]);opp(v[i+1],v[i+2]);

return 1;

}

if(i2<=j2&&j2<=k2){

opp(v[i+1],v[i+2]);opp(v[i],v[i+1]);

return 1;

}

return 0;

}

int main(){

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

int t;

cin>>t;

while(t--){

int n;

cin>>n;

vector<int> v(n);

int flag=1;

for(auto &i:v) cin>>i;

if(n==2){

if(v[0]<=v[1]) cout<<"YES"<<"\n";

else cout<<"NO"<<"\n";

}

else{

for(int i =0 ; i<n-2 ;i++){

flag = can3be(v,i);

if(flag==0) break;

}

if(flag) cout<<"YES"<<"\n";

else cout<<"NO"<<"\n";

}

}

}

Code 2:
#include<bits/stdc++.h>

using namespace std;

void opp(int &i,int &j){

int k=min(i,j);

i-=k;

j-=k;

}

int can3be(vector<int> &v,int i){

int i1=v[i],j1=v[i+1],k1=v[i+2];

int i2=v[i],j2=v[i+1],k2=v[i+2];

opp(i1,j1);opp(j1,k1);

opp(j2,k2);opp(i2,j2);

if(i1<=j1&&j1<=k1){

opp(v[i],v[i+1]);opp(v[i+1],v[i+2]);

return 1;

}

if(i2<=j2&&j2<=k2){

opp(v[i+1],v[i+2]);opp(v[i],v[i+1]);

return 1;

}

return 0;

}

int main(){

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

int t;

cin>>t;

while(t--){

int n;

cin>>n;

vector<int> v(n);

int flag=1;

for(auto &i:v) cin>>i;

for(int i =0 ; i<n-2 ;i++){

flag = can3be(v,i);

if(flag==0) break;

}

if(flag) cout<<"YES"<<"\n";

else cout<<"NO"<<"\n";

}

}

Answer: 1
Problem: 2061D - Kevin and Numbers
Language: c++20 

Code 1:
#include <bits/stdc++.h>
using namespace std;
#define int int64_t
const int MOD = 1000000007;
#define rep(a,b,c) for(int a = b; a < c; ++a)
#define repr(a,b,c) for(int a = b; a > c; --a)

void solve (int test_case) {
    // the key is to visualize
    // to get better, work on speed - https://www.youtube.com/watch?v=BqWqzvnbnjU
    int n, m;
    cin >> n >> m;
    int a [n], b [m];
    rep (i,0,n) cin >> a[i];
    rep (i,0,m) cin >> b[i];
    multiset<int> ms;
    rep (i,0,n) ms.insert(a[i]);
    map<int, int> mp;
    rep (i,0,m) mp[b[i]] += 1;
    while (ms.size() > 1) {
        if (mp.size() == 0) {
            cout << "NO\n";
            return;
        }
        int x = *ms.begin();
        ms.erase(ms.begin());
        if (mp.find(x) != mp.end()) {
            mp[x] -= 1;
            if (mp[x] == 0) mp.erase(x);
            continue;
        }
        int y = *ms.begin();
        ms.erase(ms.begin());
        if (y - x > 1) {
            cout << "NO\n";
            return;
        } 
        int z = x + y;
        if (mp.find(z) != mp.end()) {
            mp[z] -= 1;
            if (mp[z] == 0) mp.erase(z);
        }
        else {
            ms.insert(z);
        }
    }
    if (ms.size()) {
        if (mp.size() == 0) {
            cout << "NO\n";
            return;
        }
       int x = *ms.begin();
        ms.erase(ms.begin());
        if (mp.find(x) != mp.end()) {
            mp[x] -= 1;
            if (mp[x] == 0) mp.erase(x);
        } 
        else {
            cout << "NO\n";
            return;
        }
    }
    if (mp.size()) cout << "NO\n";
    else cout << "YES\n";
}

int32_t main () {
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int test_cases = 1;
    cin >> test_cases;
    for (int i = 1; i <= test_cases; ++i) solve(i);
    return 0;
}

Code 2:
#include <bits/stdc++.h>
using namespace std;
#define int int64_t
const int MOD = 1000000007;
#define rep(a,b,c) for(int a = b; a < c; ++a)
#define repr(a,b,c) for(int a = b; a > c; --a)

void solve (int test_case) {
    // the key is to visualize
    // to get better, work on speed - https://www.youtube.com/watch?v=BqWqzvnbnjU
    int n, m;
    cin >> n >> m;
    int a [n], b [m];
    rep (i,0,n) cin >> a[i];
    rep (i,0,m) cin >> b[i];
    map<int, int> mp;
    int cnt = 0;
    rep (i,0,n) mp[a[i]] += 1, cnt += 1;
    priority_queue<int> pq;  
    rep (i,0,m) pq.push(b[i]);
    while (pq.size() && pq.size() <= cnt) {
        int x = pq.top();
        pq.pop();
        if (mp.find(x) != mp.end()) {
            mp[x] -= 1;
            if (mp[x] == 0) {
                mp.erase(x);
            }
            cnt -= 1;
        }
        else {
            pq.push(x / 2);
            pq.push(x - x / 2);
        }
    }
    if (mp.size()) cout << "NO\n";
    else cout << "YES\n";
}

int32_t main () {
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int test_cases = 1;
    cin >> test_cases;
    for (int i = 1; i <= test_cases; ++i) solve(i);
    return 0;
}

Answer: 2
Problem: 2061D - Kevin and Numbers
Language: c++17 

Code 1:
#include <bits/stdc++.h>
using namespace std;
//                                       Sk Najir
#ifndef ONLINE_JUDGE
#include "db.hpp"
#else
#define dbg(x)
#define dbg2(x, y)
#define dbg3(x, y, z)
#endif
#define IOS                      \
    ios::sync_with_stdio(false); \
    cin.tie(0);                  \
    cout.tie(0);

// pre_define
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

// shortcut type
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;

// Constants
const int MOD = 1e9 + 7;

void solve()
{
    int n, m;
    cin >> n >> m;
    multiset<ll> a, b;
    ll x;
    for (int i = 0; i < n; i++)
        cin >> x, a.insert(x);
    for (int i = 0; i < m; i++)
    {
        cin >> x;
        b.insert(x);
    }
    while (!a.empty() and *a.begin() <= *b.begin())
    {
        //dbg(b);
        x = *b.rbegin();
        b.erase(prev(b.end()));
        if (a.find(x) != a.end())
        {
            a.erase(a.find(x));
        }
        else
        {
            if (x % 2)
            {
                if (x == 1)
                {
                    cout << "No" << endl;
                    return;
                }
                b.insert(x / 2);
                b.insert((x / 2) + 1);
            }
            else
            {
                b.insert(x / 2);
                b.insert(x / 2);
            }
        }
    }
    if (a.empty() and b.empty())
    {
        cout << "Yes" << endl;
    }
    else
        cout << "No" << endl;
}

int main()
{
    IOS;
    int tc = 1;
    cin >> tc;
    for (int t = 1; t <= tc; t++)
        solve();
}

Code 2:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define vi vector<int>
#define mod 1000000007
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int nn;
    cin >> nn;
    while (nn--)
    {
        int n, m;
        cin >> n >> m;

        multiset<int> a;
        for (int i = 0; i < n; i++)
        {
            int x;
            cin >> x;
            a.insert(x);
        }

        priority_queue<int> pq;
        for (int j = 0; j < m; j++)
        {
            int x;
            cin >> x;
            pq.push(x);
        }

        while (!pq.empty() && pq.size() <= a.size())
        {
            int x = pq.top();
            pq.pop();
            // cout << x << " ";
            auto it = a.lower_bound(x);
            if (it == a.end() || *it != x)
            {
                // cout << "breaking " << x << endl;
                if (x < 2)
                {
                    pq.push(-1);
                    break;
                }
                pq.push(x / 2);
                pq.push((x + 1) / 2);
            }
            else
            {
                // cout << "erasing " << x << endl;
                a.erase(it);
            }
        }

        cout << (a.empty() && pq.empty() ? "Yes\n" : "No\n");
    }
}


Answer: 2
Problem: 2061D - Kevin and Numbers
Language: c++23 

Code 1:
#include<bits/stdc++.h>
#define int long long
using namespace std;

bool solve(){
    int n,m,x;
    cin>>n>>m;
    priority_queue<int> a,b;
    for(int i=0;i<n;i++){
        cin>>x;
        a.push(x);
    }
    for(int j=0;j<m;j++){
        cin>>x;
        b.push(x);
    }
    int flag=0;
    while(a.size()&&b.size()){
        if(a.top()>b.top()||a.size()<b.size())return 0;
        if(a.top()==b.top()){a.pop();b.pop();continue;}
        int u=b.top();
        b.pop();
        b.push(u>>1);
        b.push(u+1>>1);
    }
    return a.empty()&&b.empty();
}
signed main(){
    int t;
    cin>>t;
    while(t--){
        cout<<(solve()?"Yes":"No")<<endl;
    }
    return 0;
}

Code 2:
#include<bits/stdc++.h>
#define int long long
using namespace std;

const int N=2e5+50;
int a[N],b[N];

signed main(){
    int t;
    cin>>t;
    while(t--){
        int n,m;
        cin>>n>>m;
        map<int,int> p2;
        int sum1=0,sum2=0;
        for(int i=0;i<n;i++){
            cin>>a[i];
            sum1+=a[i];
        }
        for(int j=0;j<m;j++){
            cin>>b[j];
            p2[b[j]]++;
            sum2+=b[j];
        }
        if(sum1!=sum2){
            cout<<"No"<<endl;
            continue;
        }
        vector<int> v;
        sort(a,a+n);
        for(int i=0;i<n;i++){
            if(p2[a[i]]>=1){
                p2[a[i]]--;
            }else{
                
                if(!v.empty()){
                    if(p2[v.back()]>=1){
                        p2[v.back()]--;
                        v.pop_back();
                    }
                    if(!v.empty()&&abs(v.back()-a[i])<=1){
                        int u=v.back();
                        v.pop_back();
                        v.push_back(a[i]+u);
                     //   cout<<v.back()<<endl;
                    }else{
                        v.push_back(a[i]);
                    }
                    if(!v.empty()&&p2[v.back()]>=1){
                        p2[v.back()]--;
                        v.pop_back();
                    }
                }else{
                    v.push_back(a[i]);
                }
            }
        }
        int flag=0;
        for(auto i:p2){
            if(i.second>0){
                flag=1;
                break;
            }
        }    
        if(!v.empty()||flag){
            cout<<"No"<<endl;
        }else{
            cout<<"Yes"<<endl;
        }
    }
    return 0;
}
// 1中和相等
// 2 最大 小于 下面
// 3如果长度相等 判断 是否一样
// 4

Answer: 1
Problem: 2061D - Kevin and Numbers
Language: c++20 

Code 1:
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pp pair<int,int> 
const int N = 2e5 + 9;
const int inf = 0x3f3f3f3f3f3f3f3f;
const int mod = 998244353;


void solve() {
    int n, m;cin >> n >> m;
    map<int, int> mp;
    for (int i = 0;i < n;i++) {
        int x;cin >> x;
        mp[x]++;
    }
    priority_queue<int, vector<int>, greater<int>> pq;
    for (int i = 0;i < m;i++) {
        int x;cin >> x;
        pq.push(x);
    }
    while (pq.size()) {
        int x = pq.top();pq.pop();
        if (mp[x])mp[x]--;
        else {
            if (x == 1) {
                cout << "No\n";return;
            }
            else if (x % 2) {
                pq.push(x / 2);pq.push(x / 2+1);
            }
            else {
                pq.push(x / 2);pq.push(x / 2);
            }
        }
    }
    for(auto[x,y]:mp){
        if(y){
            cout << "No\n";return;
        }
    }
    cout << "Yes\n";
}
signed main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int _ = 1;
    cin >> _;
    while (_--)solve();
    return 0;
}

Code 2:
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pp pair<int,int> 
const int N = 2e5 + 9;
const int inf = 0x3f3f3f3f3f3f3f3f;
const int mod = 998244353;


void solve() {
    int n, m;cin >> n >> m;
    map<int, int> mp;
    priority_queue<int, vector<int>, greater<int>> pq;
    for (int i = 0;i < n;i++) {
        int a;cin >> a;pq.push(a);
    }
    for (int i = 0;i < m;i++) {
        int a;cin >> a;
        mp[a]++;
    }

    while (pq.size()>=2) {
        while (pq.size()) {
            int a = pq.top();
            if (mp[a] > 0) {
                mp[a]--;pq.pop();
            }
            else break;
        }
        if (pq.size() >= 2) {
            int a = pq.top();pq.pop();
            int b = pq.top();pq.pop();
            if (b - a <= 1) {
                pq.push(b + a);
            }
            else {
                cout << "No\n";return;
            }
        }
    }
    if (pq.size() == 1) {
        if(mp[pq.top()] > 0){mp[pq.top()]--;pq.pop();}
    }
    if(pq.size() > 0){
        cout << "No\n";return;
    }
    for (auto [x, y] : mp) {
        if(y > 0){
            cout << "No\n";return;
        }
    }
    cout << "Yes\n";
}
signed main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int _ = 1;
    cin >> _;
    while (_--)solve();
    return 0;
}

Answer: 1
Problem: 2061D - Kevin and Numbers
Language: c++20 

Code 1:
#include <bits/stdc++.h>

using namespace std;



typedef long long ll;

#define pb push_back



const int mxN = 2e5 + 5;

int a[mxN], b[mxN];



void solve(){

    int n, m; cin >> n >> m;

    ll sm = 0;

    for (int i = 0; i < n; i++) cin >> a[i], sm += a[i];

    for (int i = 0; i < m; i++) cin >> b[i], sm -= b[i];



    if(sm != 0) { cout << "NO\n"; return; }

    priority_queue<int> pqa, pqb; for (int i = 0; i < m; i++) pqb.push(b[i]); for(int i = 0; i < n; i++) pqa.push(a[i]);



    while(!pqa.empty() && !pqb.empty()){

        int x = pqa.top(); pqa.pop();

        int y = pqb.top(); pqb.pop();

        if (x == y) continue;

        if ( x > y || y == 1) { cout << "NO\n"; return; }

        pqb.push(y / 2); pqb.push((y + 1) / 2); pqa.push(x);

    }

    cout << (pqa.empty() && pqb.empty() ? "YES\n" : "NO\n");

}



int main(){

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

    int t; cin >> t;

    while(t--) solve();

    return 0;

}

Code 2:
#include <bits/stdc++.h>

using namespace std;



typedef long long ll;

#define pb push_back



const int mxN = 2e5 + 5;

int a[mxN], b[mxN];



void solve(){

    int n, m; cin >> n >> m;

    ll sm = 0;

    for (int i = 0; i < n; i++) cin >> a[i], sm += a[i];

    for (int i = 0; i < m; i++) cin >> b[i], sm -= b[i];



    if(sm != 0) { cout << "NO\n"; return; }

    priority_queue<int> pqa, pqb; for (int i = 0; i < m; i++) pqb.push(b[i]); for(int i = 0; i < n; i++) pqa.push(a[i]);



    while(!pqa.empty() && !pqb.empty()){

        int x = pqa.top(); pqa.pop();

        int y = pqb.top(); pqb.pop();

        if (x == y) continue;

        if (y == 1) { cout << "NO\n"; return; }

        pqb.push(y / 2); pqb.push((y + 1) / 2); pqa.push(x);

    }

    cout << (pqa.empty() && pqb.empty() ? "YES\n" : "NO\n");

}



int main(){

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

    int t; cin >> t;

    while(t--) solve();

    return 0;

}

Answer: 1
Problem: 2061D - Kevin and Numbers
Language: c++20 

Code 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;
}


Code 2:
#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;
}

Answer: 2
Problem: 2061D - Kevin and Numbers
Language: c++23 

Code 1:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
 
int main() {
	cin.tie(0);
	ios::sync_with_stdio(0);
	int t;
    cin >> t;
    while (t--) {
        int n, m;
        cin >> n >> m;
        multiset<ll> a, b;
        for (int i = 0; i < n; i++) {
            ll x;
            cin >> x;
            a.insert(x);
        }
        for (int i = 0; i < m; i++) {
            ll x;
            cin >> x;
            b.insert(x);
        }
        while (a.size() && b.size()) {
            if (*b.begin() == *a.begin()) {
                a.erase(a.begin());
                b.erase(b.begin());
                continue;
            }
            if (*b.begin() < *a.begin() || a.size() == 1) {
                break;
            }
            if (*next(a.begin()) - 1 > *a.begin()) {
                break;
            }
            a.insert(*a.begin() + *next(a.begin()));
            a.erase(next(a.begin()));
            a.erase(a.begin());
        }
        cout << (a.size() || b.size() ? "NO" : "YES") << "\n";
    }

	return 0;
}

Code 2:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
 
int main() {
	cin.tie(0);
	ios::sync_with_stdio(0);
	int t;
    cin >> t;
    while (t--) {
        int n, m;
        cin >> n >> m;
        multiset<ll> a, b;
        for (int i = 0; i < n; i++) {
            ll x;
            cin >> x;
            a.insert(x);
        }
        for (int i = 0; i < m; i++) {
            ll x;
            cin >> x;
            b.insert(x);
        }
        while (a.size() && b.size()) {
            if (a.lower_bound(*b.begin()) != a.end() && *a.lower_bound(*b.begin()) == *b.begin()) {
                a.erase(a.lower_bound(*b.begin()));
                b.erase(b.begin());
                continue;
            }
            if (*b.begin() < *a.begin() || a.size() == 1) {
                break;
            }
            ll x = *b.begin();
            b.erase(b.begin());
            b.insert(x / 2);
            b.insert(x / 2 + (x % 2));
        }
        cout << (a.size() || b.size() ? "NO" : "YES") << "\n";
    }

	return 0;
}

Answer: 2