ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2057B - Gorilla and the Exam
Language: C++17 (GCC 7-32)

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

typedef long long ll;

void solve() {
	ll n, k;
	cin >> n >> k;
	vector<ll> x(n);
	for (int i = 0; i < n; i++) {
		cin >> x[i];
	}
	if (k == n) {
		cout << "1\n";
		return;
	}
	sort(x.begin(), x.end());
	vector<pair<ll, ll>> v;
	for (ll i = 0; i < n; i++) {
		if (v.empty() || v.back().first != x[i]) v.push_back({x[i], 1});
		else v.back().second++;
	}

	sort(v.begin(), v.end(), [](pair<ll, ll> &a, pair<ll, ll>& b) {
		return a.second < b.second;
	});
	ll i = 0, res = 0;
	while (k > 0 || i < v.size()) {
		ll ele = v[i].first;
		ll freq = v[i].second;
		if (freq <= k) {
			k -= freq;
			v[i].second = 0;
		}
		else {
			++res;
		}
		++i;
	}
	// ll res = 0;
	// for (ll i = 0; i < v.size(); i++) {
	// 	if (v[i].second > 0) ++res;
	// }
	cout << res << "\n";
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	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() {
	ll n, k;
	cin >> n >> k;
	vector<ll> x(n);
	for (int i = 0; i < n; i++) {
		cin >> x[i];
	}
	if (k == n) {
		cout << "1\n";
		return;
	}
	sort(x.begin(), x.end());
	vector<pair<ll, ll>> v;
	for (ll i = 0; i < n; i++) {
		if (v.empty() || v.back().first != x[i]) v.push_back({x[i], 1});
		else v.back().second++;
	}

	sort(v.begin(), v.end(), [](pair<ll, ll> &a, pair<ll, ll>& b) {
		return a.second < b.second;
	});
	ll i = 0, res = 0;
	while (k > 0 || i < v.size()) {
		ll ele = v[i].first;
		ll freq = v[i].second;
		if (freq <= k) {
			k -= freq;
			v[i].second = 0;
		}
		else {
			k = 0;
			++res;
		}
		++i;
	}
	// ll res = 0;
	// for (ll i = 0; i < v.size(); i++) {
	// 	if (v[i].second > 0) ++res;
	// }
	cout << res << "\n";
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int t;
	cin >> t;
	while (t--) {
		solve();
	}
	return 0;
}
Problem: 2057B - Gorilla and the Exam
Language: C++17 (GCC 7-32)


Submission (verdict: Time limit exceeded on test 14):
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;

void solve() {
	ll n, k;
	cin >> n >> k;
	vector<ll> x(n);
	unordered_map<ll, ll> um;
	for (int i = 0; i < n; i++) {
		cin >> x[i];
		um[x[i]]++;
	}
	if (k == n) {
		cout << "1\n";
		return;
	}
	vector<pair<ll, ll>> v(um.begin(), um.end());
	sort(v.begin(), v.end(), [](pair<ll, ll> &a, pair<ll, ll>& b) {
		return a.second < b.second;
	});
	int i = 0;
	while (k > 0) {
		ll ele = v[i].first;
		ll freq = v[i].second;
		if (freq <= k) {
			k -= freq;
			v[i].second = 0;
		}
		else break;
		++i;
	}
	ll res = 0;
	for (ll i = 0; i < v.size(); i++) {
		if (v[i].second > 0) ++res;
	}
	cout << res << "\n";
}

int main() {
	int t;
	cin >> t;
	while (t--) {
		solve();
	}
	return 0;
}
Problem: 2052A - Adrenaline Rush
Language: C++17 (GCC 7-32)

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

int search(int curr[10000],int low,int high,int x){
    while(high>low){
        int mid = (low + high)/2;
        if (x == curr[mid])
            return mid;
        else if (x > curr[mid]) 
            low = mid + 1;
        else                       
        high = mid - 1;
    }
    return -1;
}
int main(){
    int n;
    cin>>n;
    int a[n],i,j;
    for(i=0;i<n;i++)
    cin>>a[i];
    reverse(a,a+n);

    int curr[n];
    for(i=0;i<n;i++)
    curr[i]=i+1;

    //implementation
    vector <pair<int,int>> vect;
    for(i=n;i>=1;i--){
        for(j=i-1;j>=1;j--){
            vect.push_back({i,j});
        }
    }

    for(i=0;i<n;i++){
        if(a[i]==curr[i])
        continue;

        int rear=search(curr,i,n,a[i]);
        int front=i;
        for(j=rear;j>front;j--){
            vect.push_back({curr[j-1],curr[j]});
            swap(curr[j],curr[j-1]);
        }
    }
    cout<<vect.size()<<endl;
    for(i=0;i<vect.size();i++){
        cout<<vect[i].first<<" "<<vect[i].second<<endl;
    }
    return 0;
}

Submission (verdict: Accepted):
#include"bits/stdc++.h"
 
using namespace std;
 
int main(){
    int n;
    cin>> n;
 
    vector<int> a(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    vector<pair<int,int>> b;
    unordered_set<int> s;
    for(auto it:a){
        for(int i=it+1;i<=n;i++){
            if(s.find(i)!=s.end()) continue;
            b.push_back({i,it});
        }
        for(int i=n;i>=1;i--){
            if(i==it || s.find(i)!=s.end()) continue;
            b.push_back({it,i});
        }
        s.insert(it);
    }
 
    cout<<b.size()<<endl;
    for(auto it:b){
        cout<<it.first<<" "<<it.second<<endl;
    }
    return 0;
}
Problem: 2052A - Adrenaline Rush
Language: C++17 (GCC 7-32)

Previous submission (verdict: Runtime error on test 7):
#include <bits/stdc++.h>
using namespace std;

int search(int curr[10000],int low,int high,int x){
    while(high>low){
        int mid = (low + high)/2;
        if (x == curr[mid])
            return mid;
        else if (x > curr[mid]) 
            low = mid + 1;
        else                       
        high = mid - 1;
    }
}
int main(){
    int n;
    cin>>n;
    int a[n],i,j;
    for(i=0;i<n;i++)
    cin>>a[i];
    reverse(a,a+n);

    int curr[n];
    for(i=0;i<n;i++)
    curr[i]=i+1;

    //implementation
    vector <pair<int,int>> vect;
    for(i=n;i>=1;i--){
        for(j=i-1;j>=1;j--){
            vect.push_back({i,j});
        }
    }

    for(i=0;i<n;i++){
        if(a[i]==curr[i])
        continue;

        int rear=search(curr,i,n,a[i]);
        int front=i;
        for(j=rear;j>front;j--){
            vect.push_back({curr[j-1],curr[j]});
            swap(curr[j],curr[j-1]);
        }
    }
    cout<<vect.size()<<endl;
    for(i=0;i<vect.size();i++){
        cout<<vect[i].first<<" "<<vect[i].second<<endl;
    }
    return 0;
}

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

int search(int curr[10000],int low,int high,int x){
    while(high>low){
        int mid = (low + high)/2;
        if (x == curr[mid])
            return mid;
        else if (x > curr[mid]) 
            low = mid + 1;
        else                       
        high = mid - 1;
    }
    return -1;
}
int main(){
    int n;
    cin>>n;
    int a[n],i,j;
    for(i=0;i<n;i++)
    cin>>a[i];
    reverse(a,a+n);

    int curr[n];
    for(i=0;i<n;i++)
    curr[i]=i+1;

    //implementation
    vector <pair<int,int>> vect;
    for(i=n;i>=1;i--){
        for(j=i-1;j>=1;j--){
            vect.push_back({i,j});
        }
    }

    for(i=0;i<n;i++){
        if(a[i]==curr[i])
        continue;

        int rear=search(curr,i,n,a[i]);
        int front=i;
        for(j=rear;j>front;j--){
            vect.push_back({curr[j-1],curr[j]});
            swap(curr[j],curr[j-1]);
        }
    }
    cout<<vect.size()<<endl;
    for(i=0;i<vect.size();i++){
        cout<<vect[i].first<<" "<<vect[i].second<<endl;
    }
    return 0;
}
Problem: 2052A - Adrenaline Rush
Language: C++17 (GCC 7-32)


Submission (verdict: Runtime error on test 7):
#include <bits/stdc++.h>
using namespace std;

int search(int curr[10000],int low,int high,int x){
    while(high>low){
        int mid = (low + high)/2;
        if (x == curr[mid])
            return mid;
        else if (x > curr[mid]) 
            low = mid + 1;
        else                       
        high = mid - 1;
    }
}
int main(){
    int n;
    cin>>n;
    int a[n],i,j;
    for(i=0;i<n;i++)
    cin>>a[i];
    reverse(a,a+n);

    int curr[n];
    for(i=0;i<n;i++)
    curr[i]=i+1;

    //implementation
    vector <pair<int,int>> vect;
    for(i=n;i>=1;i--){
        for(j=i-1;j>=1;j--){
            vect.push_back({i,j});
        }
    }

    for(i=0;i<n;i++){
        if(a[i]==curr[i])
        continue;

        int rear=search(curr,i,n,a[i]);
        int front=i;
        for(j=rear;j>front;j--){
            vect.push_back({curr[j-1],curr[j]});
            swap(curr[j],curr[j-1]);
        }
    }
    cout<<vect.size()<<endl;
    for(i=0;i<vect.size();i++){
        cout<<vect[i].first<<" "<<vect[i].second<<endl;
    }
    return 0;
}
Problem: 2060D - Subtract Min Sort
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define printarr(arr, n) for(int i=0; i<n; i++) cout<<arr[i]<<" ";
#define na cout << "NO" << endl;
#define ha cout << "YES" << endl;

int main() {
    int t;
    cin>>t;
    while(t--) {
        int n;
        cin>>n;
        vector<int> arr(n);
        for(int i=0; i<n; i++) {
            cin>>arr[i];
        }
        int isnd=1;
        for(int i=1; i<n-1; i++) {
            int minnum=min(arr[i],arr[i-1]);
            arr[i]-=minnum;
            arr[i-1]-=minnum;

            if(arr[i+1]<arr[i] || arr[i+1]<arr[i-1]) {
                isnd=0;
                break;
            }
        }
        if(n==2) {
            if(arr[0]>arr[1]) isnd=0;
        }

        if(isnd==1) ha
        else na

    }
}

Submission (verdict: Accepted):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define printarr(arr, n) for(int i=0; i<n; i++) cout<<arr[i]<<" ";
#define na cout << "NO" << endl;
#define ha cout << "YES" << endl;

int main() {
    int t;
    cin>>t;
    while(t--) {
        int n;
        cin>>n;
        vector<int> arr(n);
        for(int i=0; i<n; i++) {
            cin>>arr[i];
        }
        int isnd=1;
        for(int i=1; i<n-1; i++) {
            int minnum=min(arr[i],arr[i-1]);
            if(minnum!=arr[i-1]) {
                isnd=0;
                break;
            }
            arr[i]-=minnum;
            arr[i-1]-=minnum;

            if(arr[i+1]<arr[i] || arr[i+1]<arr[i-1] ) {
                isnd=0;
                break;
            }
        }
        if(n==2) {
            if(arr[0]>arr[1]) isnd=0;
        }

        if(isnd==1) ha
        else na

    }
}
Problem: 2060D - Subtract Min Sort
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define printarr(arr, n) for(int i=0; i<n; i++) cout<<arr[i]<<" ";
#define na cout << "NO" << endl;
#define ha cout << "YES" << endl;

int main() {
    int t;
    cin>>t;
    while(t--) {
        int n;
        cin>>n;
        vector<int> arr(n);
        for(int i=0; i<n; i++) {
            cin>>arr[i];
        }
        int isnd=1;
        for(int i=1; i<n-1; i++) {
            int minnum=min(arr[i],arr[i-1]);
            arr[i]-=minnum;
            arr[i-1]-=minnum;

            if(arr[i+1]<arr[i]) {
                isnd=0;
                break;
            }
        }
        if(n==2) {
            if(arr[0]>arr[1]) isnd=0;
        }

        if(isnd==1) ha
        else na

    }
}

Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define printarr(arr, n) for(int i=0; i<n; i++) cout<<arr[i]<<" ";
#define na cout << "NO" << endl;
#define ha cout << "YES" << endl;

int main() {
    int t;
    cin>>t;
    while(t--) {
        int n;
        cin>>n;
        vector<int> arr(n);
        for(int i=0; i<n; i++) {
            cin>>arr[i];
        }
        int isnd=1;
        for(int i=1; i<n-1; i++) {
            int minnum=min(arr[i],arr[i-1]);
            arr[i]-=minnum;
            arr[i-1]-=minnum;

            if(arr[i+1]<arr[i] || arr[i+1]<arr[i-1]) {
                isnd=0;
                break;
            }
        }
        if(n==2) {
            if(arr[0]>arr[1]) isnd=0;
        }

        if(isnd==1) ha
        else na

    }
}
Problem: 2060D - Subtract Min Sort
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define printarr(arr, n) for(int i=0; i<n; i++) cout<<arr[i]<<" ";
#define na cout << "NO" << endl;
#define ha cout << "YES" << endl;

int main() {
    int t;
    cin>>t;
    while(t--) {
        int n;
        cin>>n;
        vector<int> arr(n);
        for(int i=0; i<n; i++) {
            cin>>arr[i];
        }
        int isnd=1;
        for(int i=1; i<n-1; i++) {
            int minnum=min(arr[i],arr[i-1]);
            arr[i]-=minnum;
            arr[i-1]-=minnum;

            if(arr[i+1]<arr[i]) {
                isnd=0;
                break;
            }
        }

        if(isnd==1) ha
        else na

    }
}

Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define printarr(arr, n) for(int i=0; i<n; i++) cout<<arr[i]<<" ";
#define na cout << "NO" << endl;
#define ha cout << "YES" << endl;

int main() {
    int t;
    cin>>t;
    while(t--) {
        int n;
        cin>>n;
        vector<int> arr(n);
        for(int i=0; i<n; i++) {
            cin>>arr[i];
        }
        int isnd=1;
        for(int i=1; i<n-1; i++) {
            int minnum=min(arr[i],arr[i-1]);
            arr[i]-=minnum;
            arr[i-1]-=minnum;

            if(arr[i+1]<arr[i]) {
                isnd=0;
                break;
            }
        }
        if(n==2) {
            if(arr[0]>arr[1]) isnd=0;
        }

        if(isnd==1) ha
        else na

    }
}
Problem: 2060D - Subtract Min Sort
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define printarr(arr, n) for(int i=0; i<n; i++) cout<<arr[i]<<" ";
#define na cout << "NO" << endl;
#define ha cout << "YES" << endl;

int main() {
    int t;
    cin>>t;
    while(t--) {
        int n;
        cin>>n;
        vector<int> arr(n);
        for(int i=0; i<n; i++) {
            cin>>arr[i];
        }
        int isnd=1;
        for(int i=1; i<n-1; i++) {
            int minnum=min(arr[i],arr[i-1]);
            arr[i]-=minnum;
            arr[i-1]-=minnum;

            if(arr[i+1]<arr[i]) {
                isnd=0;
                break;
            }
        }

        if(isnd==1) ha
        else na

    }
}
Problem: 2063C - Remove Exactly Two
Language: C++17 (GCC 7-32)


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

int M = 1000000007;


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

    int t;
    cin>>t;

    while(t--){
        int n;
        cin>>n;

        vector<vector<int>> v(n);

        for(int i=0; i<n-1; ++i){
            int a, b;
            cin>>a>>b;
            v[a-1].push_back(b);
            v[b-1].push_back(a);
        }
        vector<pair<int, int>> mm(n);
        for(int i=0; i<n; ++i){
            int m=0;
            int mi=-1;
            for(int j=0; j<v[i].size(); ++j){
                m++;
                
            }
            mm[i] = {m , i};
        }

        sort(mm.begin(), mm.end());
        int m1=mm[n-1].second+1;
        vector<pair<int, int>> mm1(n);
        for(int i=0; i<n; ++i){
            int m=0;
            int mi=-1;
            if(m1==i+1) {mm1[i]={-1,i};continue;}
            for(int j=0; j<v[i].size(); ++j){
                if(v[i][j]==m1) continue;
                m++;
                
            }
            mm1[i] = {m , i};
        }
        sort(mm1.begin(), mm1.end());
        int m2= mm1[n-1].second+1;
        //m2=1;

        //cout<<"m1 "<<m1<<"m2 "<<m2<<"\n";
        int rem=0;
        unordered_map<int, int> umap;
        for(int i=0; i<n; ++i){
            int cnt=0;
            
            if(i+1==m1 || i+1==m2) {continue;}
            for(int j=0; j<v[i].size(); ++j){
                if(v[i][j]==m1 || v[i][j]==m2) continue;
                cnt++;
                umap[v[i][j]]++;
            }   

            if(cnt==0) rem++;
            else if(umap.find(i+1)==umap.end()){
                rem++;
            }

        }
        //cout<<"rem "<<rem<<"\n";

        cout<<rem<<"\n";


    }

    

    

    return 0;

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

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

void sol(){
   int n , m; cin >> n >> m;
   vector<ll> a(n) , b(m);
   map<int , int> mp;
   for(auto &it : a)cin >> it , mp[it]++;
   for(auto &it : b)cin >> it;

   vector<ll> ans;
   // ll  min = 

   int i = 0;

   while(i < b.size()){
      if(b.size() > n){
         break;
      }

      if(mp[b[i]]){
         ans.push_back(b[i]);
         i++;
         continue;
      }
      ll x = b[i] / 2;
      ll y = b[i] / 2;
      if(b[i] & 1)y++;
      if(mp[x]){
         ans.push_back(x);
         mp[x]--;
      }else{
         if(x <= 1){
            break;
         }
         b.push_back(x);
      }
      if(mp[y]){
         ans.push_back(y);
         mp[y]--;
      }else{
         if(x <= 1){
            break;
         }
         b.push_back(y);         
      }
      i++;

   }
   // cout << "YES" <<endl;
   sort(ans.begin() , ans.end());
   sort(a.begin() , a.end());
   if(a == ans){
      cout << "YES" << endl;
   }else{
      cout << "NO" << endl;
   }

   // for(auto &it : ans)cout << it <<" ";
   // cout << endl;


}

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

   int TC = 1; 
   cin >> TC;
   while(TC--) sol();
}



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

void sol(){
   int n , m; cin >> n >> m;
   vector<ll> a(n) , b(m);
   map<int , int> mp;
   for(auto &it : a)cin >> it , mp[it]++;
   for(auto &it : b)cin >> it;

   vector<ll> ans;
   // ll  min = 

   int i = 0;

   while(i < b.size()){
      if(ans.size() >= n or b.size() > n){
         cout << "NO" << endl;
         return;
      }


      if(mp[b[i]]){
         ans.push_back(b[i]);
         i++;
         continue;
      }
      ll x = b[i] / 2;
      ll y = b[i] / 2;
      if(b[i] & 1)y++;
      if(mp[x]){
         ans.push_back(x);
         mp[x]--;
      }else{
         if(x <= 1){
            break;
         }
         b.push_back(x);
      }
      if(mp[y]){
         ans.push_back(y);
         mp[y]--;
      }else{
         if(x <= 1){
            break;
         }
         b.push_back(y);         
      }
      i++;

   }
   // cout << "YES" <<endl;
   sort(ans.begin() , ans.end());
   sort(a.begin() , a.end());
   if(a == ans){
      cout << "YES" << endl;
   }else{
      cout << "NO" << endl;
   }

   // for(auto &it : ans)cout << it <<" ";
   // cout << endl;


}

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

   int TC = 1; 
   cin >> TC;
   while(TC--) sol();
}
Problem: 2061D - Kevin and Numbers
Language: C++20 (GCC 13-64)


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

void sol(){
   int n , m; cin >> n >> m;
   vector<ll> a(n) , b(m);
   map<int , int> mp;
   for(auto &it : a)cin >> it , mp[it]++;
   for(auto &it : b)cin >> it;

   vector<ll> ans;
   // ll  min = 

   int i = 0;

   while(i < b.size()){
      if(b.size() > n){
         break;
      }

      if(mp[b[i]]){
         ans.push_back(b[i]);
         i++;
         continue;
      }
      ll x = b[i] / 2;
      ll y = b[i] / 2;
      if(b[i] & 1)y++;
      if(mp[x]){
         ans.push_back(x);
         mp[x]--;
      }else{
         if(x <= 1){
            break;
         }
         b.push_back(x);
      }
      if(mp[y]){
         ans.push_back(y);
         mp[y]--;
      }else{
         if(x <= 1){
            break;
         }
         b.push_back(y);         
      }
      i++;

   }
   // cout << "YES" <<endl;
   sort(ans.begin() , ans.end());
   sort(a.begin() , a.end());
   if(a == ans){
      cout << "YES" << endl;
   }else{
      cout << "NO" << endl;
   }

   // for(auto &it : ans)cout << it <<" ";
   // cout << endl;


}

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

   int TC = 1; 
   cin >> TC;
   while(TC--) sol();
}
Problem: 2061D - Kevin and Numbers
Language: C++20 (GCC 13-64)

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

void sol(){
   int n , m; cin >> n >> m;
   vector<ll> a(n) , b(m);
   map<int , int> mp;
   for(auto &it : a)cin >> it , mp[it]++;
   for(auto &it : b)cin >> it;

   vector<ll> ans;
   // ll  min = 

   int i = 0;

   while(i < b.size()){
      if(ans.size() >= n or b.size() > n){
         cout << "NO" << endl;
         return;
      }


      if(mp[b[i]]){
         ans.push_back(b[i]);
         mp[b[i]]--;
         i++;
         continue;
      }
      ll x = b[i] / 2;
      ll y = b[i] / 2;
      if(b[i] & 1)y++;
      if(mp[x]){
         ans.push_back(x);
         mp[x]--;
      }else{
         if(x <= 1){
            break;
         }
         b.push_back(x);
      }
      if(mp[y]){
         ans.push_back(y);
         mp[y]--;
      }else{
         if(x <= 1){
            break;
         }
         b.push_back(y);         
      }
      i++;

   }
   // cout << "YES" <<endl;
   sort(ans.begin() , ans.end());
   sort(a.begin() , a.end());
   if(a == ans){
      cout << "YES" << endl;
   }else{
      cout << "NO" << endl;
   }

   // for(auto &it : ans)cout << it <<" ";
   // cout << endl;


}

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

   int TC = 1; 
   cin >> TC;
   while(TC--) sol();
}



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

void sol(){
   int n , m; cin >> n >> m;
   vector<ll> a(n) , b(m);
   map<int , int> mp;
   for(auto &it : a)cin >> it , mp[it]++;
   for(auto &it : b)cin >> it;

   vector<ll> ans;
   // ll  min = 

   int i = 0;

   while(i < b.size()){
      if(ans.size() >= n or b.size() > n){
         cout << "NO" << endl;
         return;
      }


      if(mp[b[i]]){
         ans.push_back(b[i]);
         mp[b[i]]--;
         i++;
         continue;
      }
      ll x = b[i] / 2;
      ll y = b[i] / 2;
      if(b[i] & 1)y++;
      if(mp[x]){
         ans.push_back(x);
         mp[x]--;
      }else{
         if(x <= 1){
            cout << "NO" << endl;
            return;
         }
         b.push_back(x);
      }
      if(mp[y]){
         ans.push_back(y);
         mp[y]--;
      }else{
         if(x <= 1){
            cout << "NO" << endl;
            return;
         }
         b.push_back(y);         
      }
      i++;

   }
   // cout << "YES" <<endl;
   sort(ans.begin() , ans.end());
   sort(a.begin() , a.end());
   if(a == ans){
      cout << "YES" << endl;
   }else{
      cout << "NO" << endl;
   }

   // for(auto &it : ans)cout << it <<" ";
   // cout << endl;


}

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

   int TC = 1; 
   cin >> TC;
   while(TC--) sol();
}