ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2060D - Subtract Min Sort
Language: C++17 (GCC 7-32)

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

using namespace std;

typedef long long ll;

typedef long double lld;



int main() {

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    cout.tie(NULL);



    ll t;

    cin>>t;

    //t=1;



    while(t--){

        ll n;

        cin>>n;

        ll num[n];

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

            cin>>num[i];

        }

        bool check=true;

        ll temp=0;

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

            if(num[i]>num[i+1]){

                temp++;

                if(temp==2){

                    check=false;

                    break;

                }

            }

            else temp=0;

        }

        if(num[0]>num[1])check=false;

        if(check)cout<<"YES";

        else cout<<"NO";



        cout<<"\n";

    }

    return 0;

}



Submission (verdict: Accepted):
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

typedef long double lld;



int main() {

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    cout.tie(NULL);



    ll t;

    cin>>t;

    //t=1;



    while(t--){

        ll n;

        cin>>n;

        ll num[n];

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

            cin>>num[i];

        }

        bool check=true;

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

            if(num[i]>num[i+1]){

                check=false;

                break;

            }

            else{

                num[i+1]-=num[i];

            }

        }

        if(check)cout<<"YES";

        else cout<<"NO";



        cout<<"\n";

    }

    return 0;

}
Problem: 2060D - Subtract Min Sort
Language: C++17 (GCC 7-32)

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

using namespace std;

typedef long long ll;

typedef long double lld;



int main() {

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    cout.tie(NULL);



    ll t;

    cin>>t;

    //t=1;



    while(t--){

        ll n;

        cin>>n;

        ll num[n];

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

            cin>>num[i];

        }

        bool check=true;

        ll temp=0;

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

            if(num[i]>num[i+1]){

                temp++;

                if(temp==2){

                    check=false;

                    break;

                }

            }

            else temp=0;

        }

        if(check)cout<<"YES";

        else cout<<"NO";



        cout<<"\n";

    }

    return 0;

}



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

using namespace std;

typedef long long ll;

typedef long double lld;



int main() {

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    cout.tie(NULL);



    ll t;

    cin>>t;

    //t=1;



    while(t--){

        ll n;

        cin>>n;

        ll num[n];

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

            cin>>num[i];

        }

        bool check=true;

        ll temp=0;

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

            if(num[i]>num[i+1]){

                temp++;

                if(temp==2){

                    check=false;

                    break;

                }

            }

            else temp=0;

        }

        if(num[0]>num[1])check=false;

        if(check)cout<<"YES";

        else cout<<"NO";



        cout<<"\n";

    }

    return 0;

}
Problem: 2060D - Subtract Min Sort
Language: C++17 (GCC 7-32)


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

using namespace std;

typedef long long ll;

typedef long double lld;



int main() {

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    cout.tie(NULL);



    ll t;

    cin>>t;

    //t=1;



    while(t--){

        ll n;

        cin>>n;

        ll num[n];

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

            cin>>num[i];

        }

        bool check=true;

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

            if(num[i]>num[i+1]){

                check=false;

                break;

            }

        }

        if(check)cout<<"YES";

        else cout<<"NO";



        cout<<"\n";

    }

    return 0;

}
Problem: 2060D - Subtract Min Sort
Language: C++17 (GCC 7-32)

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

using namespace std;

typedef long long ll;

typedef long double lld;



int main() {

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    cout.tie(NULL);



    ll t;

    cin>>t;

    //t=1;



    while(t--){

        ll n;

        cin>>n;

        ll num[n];

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

            cin>>num[i];

        }

        bool check=true;

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

            if(num[i]>num[i+1]){

                check=false;

                break;

            }

        }

        if(check)cout<<"YES";

        else cout<<"NO";



        cout<<"\n";

    }

    return 0;

}



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

using namespace std;

typedef long long ll;

typedef long double lld;



int main() {

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    cout.tie(NULL);



    ll t;

    cin>>t;

    //t=1;



    while(t--){

        ll n;

        cin>>n;

        ll num[n];

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

            cin>>num[i];

        }

        bool check=true;

        ll temp=0;

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

            if(num[i]>num[i+1]){

                temp++;

                if(temp==2){

                    check=false;

                    break;

                }

            }

            else temp=0;

        }

        if(check)cout<<"YES";

        else cout<<"NO";



        cout<<"\n";

    }

    return 0;

}
Problem: 2060D - Subtract Min Sort
Language: C++17 (GCC 7-32)

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

long long max(long long a, long long b){
    return (a>b)?a:b;
}

long long min(long long a, long long b){
    return (a<b)?a:b;
}

int max(int a, int b){
    return (a>b)?a:b;
}

int min(int a, int b){
    return (a<b)?a:b;
}



void soln(){
    int n, p, q, r, s;
    long long a, b, c, d;
    bool flag = true;
    cin>>n;
    vector<long long> v(n), temp;
    for(int i = 0; i<n; i++) cin>>v[i];
    for(int i = n-2; i>0; i--){
        if(v[i]>v[i+1]){
            if(v[i-1]>=v[i]){
                v[i-1] = v[i-1]-v[i];
                v[i] = 0;
            }
            else{
                if(v[i]-v[i-1]>v[i]-v[i+1]){
                    cout<<"NO"<<endl;
                    return;
                }
                else{
                    v[i] = v[i]-v[i-1];
                    v[i-1] = 0;
                }
            }
        }
    }
    if(n>1){
        if(v[0]<v[1]) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
    else cout<<"YES"<<endl;








    
}

int main()
{
    int t;
    cin >> t;
    for (int i = 0; i < t; i++)
        soln();
}




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

long long max(long long a, long long b){
    return (a>b)?a:b;
}

long long min(long long a, long long b){
    return (a<b)?a:b;
}

int max(int a, int b){
    return (a>b)?a:b;
}

int min(int a, int b){
    return (a<b)?a:b;
}



void soln(){
    int n, p, q, r, s;
    long long a, b, c, d;
    bool flag = true;
    cin>>n;
    vector<long long> v(n), temp;
    for(int i = 0; i<n; i++) cin>>v[i];
    for(int i = n-2; i>0; i--){
        if(v[i]>v[i+1]){
            if(v[i-1]>=v[i]){
                v[i-1] = v[i-1]-v[i];
                v[i] = 0;
            }
            else{
                if(v[i]-v[i-1]>v[i+1]){
                    cout<<"NO"<<endl;
                    return;
                }
                else{
                    v[i] = v[i]-v[i-1];
                    v[i-1] = 0;
                }
            }
        }
    }
    if(n>1){
        if(v[0]<v[1]) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
    else cout<<"YES"<<endl;








    
}

int main()
{
    int t;
    cin >> t;
    for (int i = 0; i < t; i++)
        soln();
}
Problem: 2060D - Subtract Min Sort
Language: C++17 (GCC 7-32)


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

long long max(long long a, long long b){
    return (a>b)?a:b;
}

long long min(long long a, long long b){
    return (a<b)?a:b;
}

int max(int a, int b){
    return (a>b)?a:b;
}

int min(int a, int b){
    return (a<b)?a:b;
}



void soln(){
    int n, p, q, r, s;
    long long a, b, c, d;
    bool flag = true;
    cin>>n;
    vector<long long> v(n), temp;
    for(int i = 0; i<n; i++) cin>>v[i];
    for(int i = n-2; i>0; i--){
        if(v[i]>v[i+1]){
            if(v[i-1]>=v[i]){
                v[i-1] = v[i-1]-v[i];
                v[i] = 0;
            }
            else{
                if(v[i]-v[i-1]>v[i]-v[i+1]){
                    cout<<"NO"<<endl;
                    return;
                }
                else{
                    v[i] = v[i]-v[i-1];
                    v[i-1] = 0;
                }
            }
        }
    }
    if(n>1){
        if(v[0]<v[1]) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
    else cout<<"YES"<<endl;








    
}

int main()
{
    int t;
    cin >> t;
    for (int i = 0; i < t; i++)
        soln();
}
Problem: 2060D - Subtract Min Sort
Language: C++17 (GCC 7-32)

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

long long max(long long a, long long b){
    return (a>b)?a:b;
}

long long min(long long a, long long b){
    return (a<b)?a:b;
}

int max(int a, int b){
    return (a>b)?a:b;
}

int min(int a, int b){
    return (a<b)?a:b;
}



void soln(){
    int n, p, q, r, s;
    long long a, b, c, d;
    bool flag = true;
    cin>>n;
    vector<long long> v(n), temp;
    for(int i = 0; i<n; i++) cin>>v[i];
    for(int i = n-2; i>0; i--){
        if(v[i]>v[i+1]){
            if(v[i-1]>=v[i]){
                v[i-1] = v[i-1]-v[i];
                v[i] = 0;
            }
            else{
                if(v[i]-v[i-1]>v[i+1]){
                    cout<<"NO"<<endl;
                    return;
                }
                else{
                    v[i] = v[i]-v[i-1];
                    v[i-1] = 0;
                }
            }
        }
    }
    if(n>1){
        if(v[0]<v[1]) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
    else cout<<"YES"<<endl;








    
}

int main()
{
    int t;
    cin >> t;
    for (int i = 0; i < t; i++)
        soln();
}




Submission (verdict: Accepted):
#include <bits/stdc++.h>
using namespace std;

long long max(long long a, long long b){
    return (a>b)?a:b;
}

long long min(long long a, long long b){
    return (a<b)?a:b;
}

int max(int a, int b){
    return (a>b)?a:b;
}

int min(int a, int b){
    return (a<b)?a:b;
}



void soln(){
    int n, p, q, r, s;
    long long a, b, c, d;
    bool flag = true;
    cin>>n;
    vector<long long> v(n), temp;
    for(int i = 0; i<n; i++) cin>>v[i];
    for(int i = 0; i<n-1; i++){
        if(v[i]>v[i+1]){
            cout<<"NO"<<endl;
            return;
        }
        else{
            v[i+1] = v[i+1]-v[i];
            v[i] = 0;
        }
    }
    cout<<"YES"<<endl;








    
}

int main()
{
    int t;
    cin >> t;
    for (int i = 0; i < t; i++)
        soln();
}
Problem: 2050C - Uninteresting Number
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 3):
#include<bits/stdc++.h>
using namespace std;
using ll = long long int;
int main(){
    int t;
    cin>>t;
    while(t--){
    string s;
    cin>>s;
    int a=0,b=0;
    ll sum=0;
    for(int i=0;i<s.size();i++){
        if(s[i]=='2')a++;
        else if(s[i]=='3')b++;
        sum+=s[i]-'0';
    }
   
    int f=0;
       for(int i=0;i<= min(10,a);i++){
         for(int j=0;j<=min(10,b);j++){
             if((sum+i*2+j*6)%9==0){
                cout<<"YES"<<endl;
                f=1;
                break;
             }
         }
      }
      if(!f)cout<<"NO"<<endl;


    }
}

Submission (verdict: Wrong answer on test 3):
#include<bits/stdc++.h>
using namespace std;
using ll = long long int;
int main(){
    int t;
    cin>>t;
    while(t--){
    string s;
    cin>>s;
    int a=0,b=0;
    ll sum=0;
    for(int i=0;i<s.size();i++){
        if(s[i]=='2'&&a<8)a++;
        else if(s[i]=='3'&&b<8)b++;
        sum+=s[i]-'0';
    }
   
    int f=0;
       for(int i=0;i<= min(10,a);i++){
         for(int j=0;j<=min(10,b);j++){
             if((sum+i*2+j*6)%9==0){
                cout<<"YES"<<endl;
                f=1;
                break;
             }
         }
      }
      if(!f)cout<<"NO"<<endl;


    }
}
Problem: 2050C - Uninteresting Number
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 3):
#include<bits/stdc++.h>
using namespace std;
using ll = long long int;
int main(){
    int t;
    cin>>t;
    while(t--){
    ll n;
    cin>>n;
    ll sum=0;
    int a=0,b=0;
    while(n>0){
        if(n%10==2)a++;
        else if(n%10==3)b++;
        sum+=(n%10);
        n/=10;
    }
    int f=0;
       for(int i=0;i<=a;i++){
         for(int j=0;j<=b;j++){
             if((sum+i*2+j*6)%9==0){
                cout<<"YES"<<endl;
                f=1;
                break;
             }
         }
      }
      if(!f)cout<<"NO"<<endl;


    }
}
Problem: 2050C - Uninteresting Number
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 3):
#include<bits/stdc++.h>
using namespace std;
using ll = long long int;
int main(){
    int t;
    cin>>t;
    while(t--){
    string s;
    cin>>s;
    int a=0,b=0;
    ll sum=0;
    for(int i=0;i<s.size();i++){
        if(s[i]=='2'&&a<8)a++;
        else if(s[i]=='3'&&b<8)b++;
        sum+=s[i]-'0';
    }
   
    int f=0;
       for(int i=0;i<= min(10,a);i++){
         for(int j=0;j<=min(10,b);j++){
             if((sum+i*2+j*6)%9==0){
                cout<<"YES"<<endl;
                f=1;
                break;
             }
         }
      }
      if(!f)cout<<"NO"<<endl;


    }
}

Submission (verdict: Accepted):
#include<bits/stdc++.h>
using namespace std;
using ll = long long int;
int main(){
    int t;
    cin>>t;
    while(t--){
    string s;
    cin>>s;
    int a=0,b=0;
    ll sum=0;
    for(int i=0;i<s.size();i++){
        if(s[i]=='2')a++;
        else if(s[i]=='3')b++;
        sum+=s[i]-'0';
    }
   
    int f=0;
       for(int i=0;i<=a;i++){
         for(int j=0;j<=b;j++){
             if((sum+i*2+j*6)%9==0){
                cout<<"YES"<<endl;
                f=1;
                break;
             }
           
         }
           if(f)break;
      }
      if(!f)cout<<"NO"<<endl;


    }
}
Problem: 2050C - Uninteresting Number
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 3):
#include<bits/stdc++.h>
using namespace std;
using ll = long long int;
int main(){
    int t;
    cin>>t;
    while(t--){
    string s;
    cin>>s;
    ll a=0,b=0;
    ll sum=0;
    for(int i=0;i<s.size();i++){
        if(s[i]=='2')a++;
        else if(s[i]=='3')b++;
        sum+=s[i]-'0';
    }
   
    int f=0;
       for(int i=0;i<=a;i++){
         for(int j=0;j<=b;j++){
             if((sum+i*2+j*6)%9==0){
                cout<<"YES"<<endl;
                f=1;
                break;
             }
         }
      }
      if(!f)cout<<"NO"<<endl;


    }
}

Submission (verdict: Wrong answer on test 3):
#include<bits/stdc++.h>
using namespace std;
using ll = long long int;
int main(){
    int t;
    cin>>t;
    while(t--){
    string s;
    cin>>s;
    int a=0,b=0;
    ll sum=0;
    for(int i=0;i<s.size();i++){
        if(s[i]=='2')a++;
        else if(s[i]=='3')b++;
        sum+=s[i]-'0';
    }
   
    int f=0;
       for(int i=0;i<= min(10,a);i++){
         for(int j=0;j<=min(10,b);j++){
             if((sum+i*2+j*6)%9==0){
                cout<<"YES"<<endl;
                f=1;
                break;
             }
         }
      }
      if(!f)cout<<"NO"<<endl;


    }
}
Problem: 2050C - Uninteresting Number
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 3):
#include<bits/stdc++.h>
using namespace std;
using ll = long long int;
int main(){
    int t;
    cin>>t;
    while(t--){
    ll n;
    cin>>n;
    ll sum=0;
    int a=0,b=0;
    while(n>0){
        if(n%10==2)a++;
        else if(n%10==3)b++;
        sum+=(n%10);
        n/=10;
    }
    int f=0;
       for(int i=0;i<=a;i++){
         for(int j=0;j<=b;j++){
             if((sum+i*2+j*6)%9==0){
                cout<<"YES"<<endl;
                f=1;
                break;
             }
         }
      }
      if(!f)cout<<"NO"<<endl;


    }
}

Submission (verdict: Wrong answer on test 3):
#include<bits/stdc++.h>
using namespace std;
using ll = long long int;
int main(){
    int t;
    cin>>t;
    while(t--){
    string s;
    cin>>s;
    ll a=0,b=0;
    ll sum=0;
    for(int i=0;i<s.size();i++){
        if(s[i]=='2')a++;
        else if(s[i]=='3')b++;
        sum+=s[i]-'0';
    }
   
    int f=0;
       for(int i=0;i<=a;i++){
         for(int j=0;j<=b;j++){
             if((sum+i*2+j*6)%9==0){
                cout<<"YES"<<endl;
                f=1;
                break;
             }
         }
      }
      if(!f)cout<<"NO"<<endl;


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

Previous submission (verdict: Time limit exceeded on test 3):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void solve() {
    int n,m;cin>>n>>m;
    vector<ll> a(n),b(m);
    ll suma=0,sumb=0;
    for(int i=0;i<n;++i) cin>>a[i],suma+=a[i];
    for(int i=0;i<m;++i) cin>>b[i],sumb+=b[i];
    if(suma!=sumb){
        cout<<"No"<<'\n';
        return;
    }
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    map<ll,ll> mp;
    for(int i=0;i<n;++i){
        mp[a[i]]++;
    }
    while(1){
        for(int i=0;i<m;++i){
            if(mp.find(b[i])!=mp.end()) continue;
            else{
                if(b[i]%2==0){
                    b[i]=b[i]/2;
                    b.push_back(b[i]);
                    m++;
                }else{
                    b[i]=b[i]/2;
                    b.push_back(b[i]+1);
                    m++;
                }
            }
            if(m>=n) break;
        }
        if(m>=n) break;
    }
    if(m>n){
        cout<<"No"<<'\n';
        return;
    }
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    for(int i=0;i<n;++i){
        if(b[i]!=a[i]){
            cout<<"No"<<'\n';
            return;
        }
    }
    cout<<"Yes"<<'\n';
    return;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}

Submission (verdict: Accepted):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void solve() {
    int n,m;cin>>n>>m;
    vector<ll> a(n),b(m);
    priority_queue<ll> ap,bp;
    for(int i=0;i<n;++i) cin>>a[i],ap.push(a[i]);
    for(int i=0;i<m;++i) cin>>b[i],bp.push(b[i]);
    //cout<<ap.size()<<bp.size()<<'\n';
    while(ap.size()!=bp.size()&&!ap.empty()&&!bp.empty()){
        ll x=ap.top(),y=bp.top();
        if(x==y){
            ap.pop();
            bp.pop();
        }else{
            if(y==1){
                cout<<"No"<<'\n';
                return;
            }
            else if(y%2==0){
                bp.pop();
                bp.push(y/2);
                bp.push(y/2);
            }else{
                bp.pop();
                bp.push(y/2);
                bp.push(y/2+1);
            }
        }
    }
    if(ap.size()!=bp.size()){
        cout<<"No"<<'\n';
        return;
    }
    //cout<<ap.size()<<'\n';
    while(ap.size()){
        ll x=ap.top(),y=bp.top();
        if(x!=y){
            cout<<"No"<<'\n';
            return;
        }else{
            ap.pop();
            bp.pop();
        }
    }
    cout<<"Yes"<<'\n';
    return;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t;
    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 3):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void solve() {
    int n,m;cin>>n>>m;
    vector<ll> a(n),b(m);
    ll suma=0,sumb=0;
    for(int i=0;i<n;++i) cin>>a[i],suma+=a[i];
    for(int i=0;i<m;++i) cin>>b[i],sumb+=b[i];
    if(suma!=sumb){
        cout<<"No"<<'\n';
        return;
    }
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    map<ll,ll> mp;
    for(int i=0;i<n;++i){
        mp[a[i]]++;
    }
    int val=n-m;
    while(1){
        for(int i=0;i<m;++i){
            if(mp.find(b[i])!=mp.end()) continue;
            else{
                if(b[i]%2==0){
                    b[i]=b[i]/2;
                    b.push_back(b[i]);
                    m++;
                }else{
                    b[i]=b[i]/2;
                    b.push_back(b[i]+1);
                    m++;
                }
            }
            if(m==n) break;
        }
        if(m==n) break;
    }
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    for(int i=0;i<n;++i){
        if(b[i]!=a[i]){
            cout<<"No"<<'\n';
            return;
        }
    }
    cout<<"Yes"<<'\n';
    return;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}
Problem: 2061D - Kevin and Numbers
Language: C++20 (GCC 13-64)

Previous submission (verdict: Time limit exceeded on test 3):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void solve() {
    int n,m;cin>>n>>m;
    vector<ll> a(n),b(m);
    ll suma=0,sumb=0;
    for(int i=0;i<n;++i) cin>>a[i],suma+=a[i];
    for(int i=0;i<m;++i) cin>>b[i],sumb+=b[i];
    if(suma!=sumb){
        cout<<"No"<<'\n';
        return;
    }
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    map<ll,ll> mp;
    for(int i=0;i<n;++i){
        mp[a[i]]++;
    }
    int val=n-m;
    while(1){
        for(int i=0;i<m;++i){
            if(mp.find(b[i])!=mp.end()) continue;
            else{
                if(b[i]%2==0){
                    b[i]=b[i]/2;
                    b.push_back(b[i]);
                    m++;
                }else{
                    b[i]=b[i]/2;
                    b.push_back(b[i]+1);
                    m++;
                }
            }
            if(m==n) break;
        }
        if(m==n) break;
    }
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    for(int i=0;i<n;++i){
        if(b[i]!=a[i]){
            cout<<"No"<<'\n';
            return;
        }
    }
    cout<<"Yes"<<'\n';
    return;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}

Submission (verdict: Time limit exceeded on test 3):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void solve() {
    int n,m;cin>>n>>m;
    vector<ll> a(n),b(m);
    ll suma=0,sumb=0;
    for(int i=0;i<n;++i) cin>>a[i],suma+=a[i];
    for(int i=0;i<m;++i) cin>>b[i],sumb+=b[i];
    if(suma!=sumb){
        cout<<"No"<<'\n';
        return;
    }
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    map<ll,ll> mp;
    for(int i=0;i<n;++i){
        mp[a[i]]++;
    }
    while(1){
        for(int i=0;i<m;++i){
            if(mp.find(b[i])!=mp.end()) continue;
            else{
                if(b[i]%2==0){
                    b[i]=b[i]/2;
                    b.push_back(b[i]);
                    m++;
                }else{
                    b[i]=b[i]/2;
                    b.push_back(b[i]+1);
                    m++;
                }
            }
            if(m>=n) break;
        }
        if(m>=n) break;
    }
    if(m>n){
        cout<<"No"<<'\n';
        return;
    }
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    for(int i=0;i<n;++i){
        if(b[i]!=a[i]){
            cout<<"No"<<'\n';
            return;
        }
    }
    cout<<"Yes"<<'\n';
    return;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}