ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2060D - Subtract Min Sort
Language: C++23 (GCC 14-64, msys2)

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

string solve() {
    int n;
    cin >> n;
    vector< int > v(n);
    for(auto &it : v) cin >> it;
    
    int flag = 1;
    for(int i = 1; i < n; i++) {
        if(v[i] < v[i - 1]) flag = 0;
    }
    if(flag) return "YES";
    
    for(int i = n - 1; i > 0; i--) {
        if(v[i] > v[i - 1]) flag = 1;
    }
    if(flag == 0) return "NO";
    
    int mini = INT_MAX;
    for(int i = 0; i < n; i++) {
        mini = min(v[i], v[i + 1]);
        v[i] -= mini;
        v[i + 1] -= mini;
    }
    
    for(int i = 1; i < n; i++) {
        if(v[i] < v[i - 1]) return "NO";
    }
    
    return "YES";
}

int main() {
    long long t;
    cin >> t;
    while(t--) {
        // solve();
        cout << solve() << "\n";
    }
}


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

string solve() {
    int n;
    cin >> n;
    vector< int > v(n);
    for(auto &it : v) cin >> it;
    
    int flag = 1;
    for(int i = 1; i < n; i++) {
        if(v[i] < v[i - 1]) flag = 0;
    }
    if(flag) return "YES";
    
    for(int i = n - 1; i > 0; i--) {
        if(v[i] > v[i - 1]) flag = 1;
    }
    if(flag == 0) return "NO";
    
    int mini = INT_MAX;
    for(int i = 0; i < n - 1; i++) {
        mini = min(v[i], v[i + 1]);
        v[i] -= mini;
        v[i + 1] -= mini;
    }
    
    for(int i = 1; i < n; i++) {
        if(v[i] < v[i - 1]) return "NO";
    }
    
    return "YES";
}

int main() {
    long long t;
    cin >> t;
    while(t--) {
        // solve();
        cout << solve() << "\n";
    }
}
Problem: 2060D - Subtract Min Sort
Language: C++23 (GCC 14-64, msys2)


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

string solve() {
    int n;
    cin >> n;
    vector< int > v(n);
    for(auto &it : v) cin >> it;
    
    int flag = 1;
    for(int i = 1; i < n; i++) {
        if(v[i] < v[i - 1]) flag = 0;
    }
    if(flag) return "YES";
    
    for(int i = n - 1; i > 0; i--) {
        if(v[i] > v[i - 1]) flag = 1;
    }
    if(flag == 0) return "NO";
    
    int mini = INT_MAX;
    for(int i = 0; i < n; i++) {
        mini = min(v[i], v[i + 1]);
        v[i] -= mini;
        v[i + 1] -= mini;
    }
    
    for(int i = 1; i < n; i++) {
        if(v[i] < v[i - 1]) return "NO";
    }
    
    return "YES";
}

int main() {
    long long t;
    cin >> t;
    while(t--) {
        // solve();
        cout << solve() << "\n";
    }
}
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;

void solve(){

    int n;

    cin >> n;

    vector<int> ar(n);

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

    {

        cin >> ar[i];

    }

    if (n == 1)

    {

        cout << 'YES' << endl;

        return;

    }

    else

    {

        if (ar[0] > ar[1])

        {

            cout << "NO" << endl;

            return;

        }

        else

        {

            int previous = ar[0];

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

            {

                if (ar[i] >= ar[i - 1])

                {

                    previous = ar[i-1];

                    continue;

                }

                int p = min(previous, ar[i - 1]);

                ar[i-1]=abs(ar[i-1]-p);

                if(ar[i-1]>ar[i]){

                    cout<<"NO"<<endl;

                    return;

                }

                previous=ar[i-1];

            }

            cout << "YES" << endl;

            return ;

        }

    }

}

int main(){

    int t;

    cin>>t;

    while(t--){

        solve();

    }

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



void solve() {

    int n;

    cin >> n;

    vector<int> ar(n);

    

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

        cin >> ar[i];

    }



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

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

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

            ar[i] -= diff * 2;

            if (ar[i] < 0) {

                cout << "NO" << endl;

                return;

            }

        }

    }

    

    cout << "YES" << endl;

}



int main() {

    ios::sync_with_stdio(false);

    cin.tie(0);

    

    int t;

    cin >> t;

    

    while (t--) {

        solve();

    }

    

    return 0;

}



Submission (verdict: Accepted):
#include <iostream>

#include <vector>

using namespace std;



void solve(){

    int n;

    cin >> n;

    vector<long long> a(n);

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

        cin >> a[i];

    }

    

    long long cur = a[0];

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

        if(cur > a[i]){

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

            return;

        }

        cur = a[i] - cur;

    }

    cout << "YES" << "\n";

}



int main(){

    ios::sync_with_stdio(false);

    cin.tie(nullptr);

    

    int t;

    cin >> t;

    while(t--){

        solve();

    }

    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;

void solve(){

    int n;

    cin >> n;

    vector<int> ar(n);

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

    {

        cin >> ar[i];

    }

    if (n == 1)

    {

        cout << 'YES' << endl;

        return;

    }

    else

    {

        if (ar[0] > ar[1])

        {

            cout << "NO" << endl;

            return;

        }

        else

        {

            int previous = ar[0];

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

            {

                if (ar[i] >= ar[i - 1])

                {

                    previous = ar[i-1];

                    continue;

                }

                int p = min(previous, ar[i - 1]);

                ar[i-1]=abs(ar[i-1]-p);

                if(ar[i-1]>ar[i]){

                    cout<<"NO"<<endl;

                    return;

                }

                previous=ar[i-1];

            }

            cout << "YES" << endl;

            return ;

        }

    }

}

int main(){

    int t;

    cin>>t;

    while(t--){

        solve();

    }

}

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

using namespace std;



void solve() {

    int n;

    cin >> n;

    vector<int> ar(n);

    

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

        cin >> ar[i];

    }



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

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

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

            ar[i] -= diff * 2;

            if (ar[i] < 0) {

                cout << "NO" << endl;

                return;

            }

        }

    }

    

    cout << "YES" << endl;

}



int main() {

    ios::sync_with_stdio(false);

    cin.tie(0);

    

    int t;

    cin >> t;

    

    while (t--) {

        solve();

    }

    

    return 0;

}
Problem: 2052A - Adrenaline Rush
Language: C++23 (GCC 14-64, msys2)

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

mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count());

const int INF = 1e18;

void Solve() 
{
	int n;
	cin >> n;
	vector<int> a(n);
	for(int &x: a) {
		cin >> x;
	}
	vector<pair<int, int> > overtakes;
	for(int i = 0; i < n; i++) {
		for(int j = i + 1; j < n; j++) {
			if(a[i] < a[j]) {
				overtakes.push_back({a[j], a[i]});
				overtakes.push_back({a[i], a[j]});
			}
			else {
				overtakes.push_back({a[i], a[j]});
			}
		}
	}
	
	cout << overtakes.size() << "\n";
	for(auto p: overtakes) {
		cout << p.first << " " << p.second << "\n";
	}
}

int32_t main() 
{
	auto begin = std::chrono::high_resolution_clock::now();
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int t = 1;
	// cin >> t;
	for(int i = 1; i <= t; i++) 
	{
		//cout << "Case #" << i << ": ";
		Solve();
	}
	auto end = std::chrono::high_resolution_clock::now();
    auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin);
    //cerr << "Time measured: " << elapsed.count() * 1e-9 << " seconds.\n"; 
	return 0;
}

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

mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count());

const int INF = 1e18;

void Solve() 
{
	int n;
	cin >> n;
	vector<int> a(n + 1), pos(n + 1);
	for(int i = 1; i <= n; i++) {
		cin >> a[i];
		pos[a[i]] = i;
	}
	vector<pair<int, int> > overtakes;
	vector<int> current_positioning;
	current_positioning.push_back(1);
	for(int i = 2; i <= n; i++) {
		for(int j = current_positioning.size() - 1; j >= 0; j--) {
			overtakes.push_back({i, current_positioning[j]});
		}
		for(int j = 0; j < current_positioning.size(); j++) {
			if(current_positioning[j] < pos[i]) {
				overtakes.push_back({current_positioning[j], i});
			}
			else {
				current_positioning.insert(current_positioning.begin() + j, i);
				break;
			}
		}

		if(current_positioning.size() == i - 1) {
			current_positioning.push_back(i);
		}
	}

	// for(int i = 0; i < n; i++) {
	// 	for(int j = i + 1; j < n; j++) {
	// 		if(a[i] < a[j]) {
	// 			overtakes.push_back({a[j], a[i]});
	// 			overtakes.push_back({a[i], a[j]});
	// 		}
	// 		else {
	// 			overtakes.push_back({a[i], a[j]});
	// 		}
	// 	}
	// }
	
	cout << overtakes.size() << "\n";
	for(auto p: overtakes) {
		cout << p.first << " " << p.second << "\n";
	}
}

int32_t main() 
{
	auto begin = std::chrono::high_resolution_clock::now();
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int t = 1;
	// cin >> t;
	for(int i = 1; i <= t; i++) 
	{
		//cout << "Case #" << i << ": ";
		Solve();
	}
	auto end = std::chrono::high_resolution_clock::now();
    auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin);
    //cerr << "Time measured: " << elapsed.count() * 1e-9 << " seconds.\n"; 
	return 0;
}
Problem: 2052A - Adrenaline Rush
Language: C++23 (GCC 14-64, msys2)


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

mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count());

const int INF = 1e18;

void Solve() 
{
	int n;
	cin >> n;
	vector<int> a(n);
	for(int &x: a) {
		cin >> x;
	}
	vector<pair<int, int> > overtakes;
	for(int i = 0; i < n; i++) {
		for(int j = i + 1; j < n; j++) {
			if(a[i] < a[j]) {
				overtakes.push_back({a[j], a[i]});
				overtakes.push_back({a[i], a[j]});
			}
			else {
				overtakes.push_back({a[i], a[j]});
			}
		}
	}
	
	cout << overtakes.size() << "\n";
	for(auto p: overtakes) {
		cout << p.first << " " << p.second << "\n";
	}
}

int32_t main() 
{
	auto begin = std::chrono::high_resolution_clock::now();
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int t = 1;
	// cin >> t;
	for(int i = 1; i <= t; i++) 
	{
		//cout << "Case #" << i << ": ";
		Solve();
	}
	auto end = std::chrono::high_resolution_clock::now();
    auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin);
    //cerr << "Time measured: " << elapsed.count() * 1e-9 << " seconds.\n"; 
	return 0;
}
Problem: 2063B - Subsequence Update
Language: C++23 (GCC 14-64, msys2)

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

void solve()
{
  int n , l , r ;
  cin >> n >> l >> r ;
  vector<long long> a(n);
  for(int i  = 0 ; i < n ; i++)
  {
    cin >> a[i] ;
  }
  vector<long long> v1 = a ; //left copy
  vector<long long> v2 = a ; //right copy
  sort(v1.begin() , v1.begin()+r) ;
  long long sum1 = accumulate(v1.begin() , v1.begin() + r - l + 1 , 0) ;
  sort(v2.begin()+l-1 , v2.end());
  long long sum2 = accumulate(v2.begin() + l - 1 , v2.begin() + r , 0) ;
  cout << (int)min(sum1,sum2) << endl ;
}

int main()
{
  std::ios::sync_with_stdio(false) ;
  std::cin.tie(nullptr) ;
  std::cout.tie(nullptr) ;
  int t ;
  std::cin >> t ;
  while(t--)
    solve() ;
  return 0 ;
}

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

void solve()
{
  int n , l , r ;
  cin >> n >> l >> r ;
  vector<long long> a(n);
  for(int i  = 0 ; i < n ; i++)
  {
    cin >> a[i] ;
  }
  vector<long long> v1 = a ; //left copy
  vector<long long> v2 = a ; //right copy
  sort(v1.begin() , v1.begin()+r) ;
  long long sum1 = 0 ;
  for(int i = 0 ; i < r-l+1 ; i++)
  {
    sum1 += v1[i] ;
  }
  /*long long sum1 = accumulate(v1.begin() , v1.begin() + r - l + 1 , 0) ;*/
  sort(v2.begin()+l-1 , v2.end());
  /*long long sum2 = accumulate(v2.begin() + l - 1 , v2.begin() + r , 0) ;*/
  long long sum2 = 0 ;
  for(int i = l-1 ; i < r ; i++)
  {
    sum2 += v2[i] ;
  }
  cout << (int)min(sum1,sum2) << endl ;
}

int main()
{
  std::ios::sync_with_stdio(false) ;
  std::cin.tie(nullptr) ;
  std::cout.tie(nullptr) ;
  int t ;
  std::cin >> t ;
  while(t--)
    solve() ;
  return 0 ;
}
Problem: 2063B - Subsequence Update
Language: C++23 (GCC 14-64, msys2)

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

void solve()
{
  int n , l , r ;
  cin >> n >> l >> r ;
  vector<long long> a(n);
  for(int i  = 0 ; i < n ; i++)
  {
    cin >> a[i] ;
  }
  vector<long long> v1 = a ; //left copy
  vector<long long> v2 = a ; //right copy
  sort(v1.begin() , v1.begin()+r) ;
  long long sum1 = 0 ;
  for(int i = 0 ; i < r-l+1 ; i++)
  {
    sum1 += v1[i] ;
  }
  /*long long sum1 = accumulate(v1.begin() , v1.begin() + r - l + 1 , 0) ;*/
  sort(v2.begin()+l-1 , v2.end());
  /*long long sum2 = accumulate(v2.begin() + l - 1 , v2.begin() + r , 0) ;*/
  long long sum2 = 0 ;
  for(int i = l-1 ; i < r ; i++)
  {
    sum2 += v2[i] ;
  }
  cout << (int)min(sum1,sum2) << endl ;
}

int main()
{
  std::ios::sync_with_stdio(false) ;
  std::cin.tie(nullptr) ;
  std::cout.tie(nullptr) ;
  int t ;
  std::cin >> t ;
  while(t--)
    solve() ;
  return 0 ;
}

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

void solve()
{
  int n , l , r ;
  cin >> n >> l >> r ;
  vector<long long> a(n);
  for(int i  = 0 ; i < n ; i++)
  {
    cin >> a[i] ;
  }
  vector<long long> v1 = a ; //left copy
  vector<long long> v2 = a ; //right copy
  sort(v1.begin() , v1.begin()+r) ;
  long long sum1 = 0 ;
  for(int i = 0 ; i < r-l+1 ; i++)
  {
    sum1 += v1[i] ;
  }
  /*long long sum1 = accumulate(v1.begin() , v1.begin() + r - l + 1 , 0) ;*/
  sort(v2.begin()+l-1 , v2.end());
  /*long long sum2 = accumulate(v2.begin() + l - 1 , v2.begin() + r , 0) ;*/
  long long sum2 = 0 ;
  for(int i = l-1 ; i < r ; i++)
  {
    sum2 += v2[i] ;
  }
  cout << (long long)min(sum1,sum2) << endl ;
}

int main()
{
  std::ios::sync_with_stdio(false) ;
  std::cin.tie(nullptr) ;
  std::cout.tie(nullptr) ;
  int t ;
  std::cin >> t ;
  while(t--)
    solve() ;
  return 0 ;
}
Problem: 2063B - Subsequence Update
Language: C++23 (GCC 14-64, msys2)

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

using namespace std ;



void solve()

{

  int n , l , r ;

  cin >> n >> l >> r ;

  vector<long long> a(n);

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

  {

    cin >> a[i] ;

  }

  vector<long long> v1 = a ; //left copy

  vector<long long> v2 = a ; //right copy

  sort(v1.begin() , v1.begin()+r) ;

  long long sum1 = accumulate(v1.begin() , v1.begin() + r - l + 1 , 0) ;

  sort(v2.begin()+l-1 , v2.end());

  long long sum2 = accumulate(v2.begin() + l - 1 , v2.begin() + l - 1 + r + l - 1 , 0) ;

  cout << (int)min(sum1,sum2) << endl ;

}



int main()

{

  std::ios::sync_with_stdio(false) ;

  std::cin.tie(nullptr) ;

  std::cout.tie(nullptr) ;

  int t ;

  std::cin >> t ;

  while(t--)

    solve() ;

  return 0 ;

}

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

void solve()
{
  int n , l , r ;
  cin >> n >> l >> r ;
  vector<long long> a(n);
  for(int i  = 0 ; i < n ; i++)
  {
    cin >> a[i] ;
  }
  vector<long long> v1 = a ; //left copy
  vector<long long> v2 = a ; //right copy
  sort(v1.begin() , v1.begin()+r) ;
  long long sum1 = accumulate(v1.begin() , v1.begin() + r - l + 1 , 0) ;
  sort(v2.begin()+l-1 , v2.end());
  long long sum2 = accumulate(v2.begin() + l - 1 , v2.begin() + r , 0) ;
  cout << (int)min(sum1,sum2) << endl ;
}

int main()
{
  std::ios::sync_with_stdio(false) ;
  std::cin.tie(nullptr) ;
  std::cout.tie(nullptr) ;
  int t ;
  std::cin >> t ;
  while(t--)
    solve() ;
  return 0 ;
}
Problem: 2063B - Subsequence Update
Language: C++23 (GCC 14-64, msys2)


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

using namespace std ;



void solve()

{

  int n , l , r ;

  cin >> n >> l >> r ;

  vector<long long> a(n);

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

  {

    cin >> a[i] ;

  }

  vector<long long> v1 = a ; //left copy

  vector<long long> v2 = a ; //right copy

  sort(v1.begin() , v1.begin()+r) ;

  long long sum1 = accumulate(v1.begin() , v1.begin() + r - l + 1 , 0) ;

  sort(v2.begin()+l-1 , v2.end());

  long long sum2 = accumulate(v2.begin() + l - 1 , v2.begin() + l - 1 + r + l - 1 , 0) ;

  cout << (int)min(sum1,sum2) << endl ;

}



int main()

{

  std::ios::sync_with_stdio(false) ;

  std::cin.tie(nullptr) ;

  std::cout.tie(nullptr) ;

  int t ;

  std::cin >> t ;

  while(t--)

    solve() ;

  return 0 ;

}
Problem: 2063B - Subsequence Update
Language: Java 21


Submission (verdict: Wrong answer on test 8):
import java.util.*;



public class B_Subsequence_Update{

    public static void main(String[] args) {

        Scanner s = new Scanner(System.in);

        int t = s.nextInt();

        while (t-->0){

            int n = s.nextInt();

            int l = s.nextInt();

            int r = s.nextInt();

            int[] arr = new int[n];

            for (int i=0;i<n;++i) arr[i] = s.nextInt();

            PriorityQueue<Integer> maxpq = new PriorityQueue<>((a,b)->b-a);

            PriorityQueue<Integer> minpql = new PriorityQueue<>();

            PriorityQueue<Integer> minpqr = new PriorityQueue<>();

            // ArrayList<Integer> raw = new ArrayList<>();

            int grr = 0;

            for (int i=l-1;i<r;++i) {

                maxpq.add(arr[i]);

                grr += arr[i];

            }

            for (int i=0;i<l-1;++i) minpql.add(arr[i]);

            for (int i=r;i<n;++i) minpqr.add(arr[i]);

            int sw = 0, sol = 0, sor = 0, ans = grr;

            while (!maxpq.isEmpty() && !minpql.isEmpty()){

                sw += maxpq.poll();

                sol += minpql.poll();

                ans = Math.min(ans,grr-sw+sol);

                // raw.add(sol);

                if (sol >= sw) break;

            }

            maxpq.clear();

            sw = 0;

            for (int i=l-1;i<r;++i) maxpq.add(arr[i]);

            while (!maxpq.isEmpty() && !minpqr.isEmpty()){

                sw += maxpq.poll();

                sor += minpqr.poll();

                ans = Math.min(ans,grr-sw+sor);

                // raw.add(sor);

                if (sor >= sw) break;

            }   

            System.out.println(ans);

        }

    }

}
Problem: 2061D - Kevin and Numbers
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 3):
#include<bits/stdc++.h>
using namespace std;
#define int long long int 
void solve(){
    int n,m;
    cin>>n>>m;
    vector<int>a(n),b(m);
    for(auto & i : a) cin>>i;
    for(auto & i : b) cin>>i;
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    unordered_set<int>sb(b.begin(),b.end());
    
    if(n<m){
        cout<<"NO"<<endl;
        return;
    }
    else if(n==m){
        if(a==b){
            cout<<"YES"<<endl;
            return;
        }
        cout<<"NO"<<endl;
        return;
    }
    vector<int>na;
    int i = 0,j = 0 ;
    int prev = 0 ;
    int sum = 0 ;
    while(i<n and j<m){
        if((abs(a[i]-sum)<=1) or (prev == 0) ){
            sum+=a[i];
            //cout<<"sum is : "<<sum<<" ";
        }
        if(sb.find(sum)!=sb.end()){
            sb.erase(sb.find(sum));
            //cout<<"yaha ayaa "<<endl;
            na.push_back(sum);
            sum=0;
            prev=0;
            j++;
        }
        else if(sum<b[j]){
            prev = sum;
        }
        
        i++;
    }
    if(i<n){
        cout<<"NO"<<endl;
        return;
        
    }
    //cout<<" kya hua "<<endl;
    if(na.empty()){
        //cout<<"khali h kya ?"<<endl;
    }
    //for(auto & it : na){
     //   cout<<it<<" ";
        
        
    //}
    //cout<<endl;
    sort(na.begin(),na.end());
    if(na==b){
        cout<<"YES"<<endl;
        return;
    }
    cout<<"NO"<<endl;
}
int32_t main(){
    int t; cin>>t;
    while(t--)  solve();
}

Submission (verdict: Runtime error on test 3):
#include<bits/stdc++.h>
using namespace std;
#define int long long int 
void solve(){
    int n,m;
    cin>>n>>m;
    vector<int>a(n),b(m);
    for(auto & i : a) cin>>i;
    for(auto & i : b) cin>>i;
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    multiset<int>sb(b.begin(),b.end());
    
    if(n<m){
        cout<<"NO"<<endl;
        return;
    }
    else if(n==m){
        if(a==b){
            cout<<"YES"<<endl;
            return;
        }
        cout<<"NO"<<endl;
        return;
    }
    vector<int>na;
    int i = 0,j = 0 ;
    int prev = 0 ;
    int sum = 0 ;
    while(i<n and j<m){
        if((abs(a[i]-sum)<=1) or (prev == 0) ){
            sum+=a[i];
            //cout<<"sum is : "<<sum<<" ";
        }
        if((sb.find(sum)!=sb.end()) or (b[j]==sum)){
            sb.erase(sb.find(sum));
            //cout<<"yaha ayaa "<<endl;
            na.push_back(sum);
            sum=0;
            prev=0;
            j++;
        }
        else if(sum<b[j]){
            prev = sum;
        }
        
        i++;
    }
    if(i<n){
        cout<<"NO"<<endl;
        return;
        
    }
    //cout<<" kya hua "<<endl;
    if(na.empty()){
       // cout<<"khali h kya ?"<<endl;
    }
    //for(auto & it : na){
    //   cout<<it<<" ";
        
        
    //}
    //cout<<endl;
    sort(na.begin(),na.end());
    if(na==b){
        cout<<"YES"<<endl;
        return;
    }
    cout<<"NO"<<endl;
}
int32_t main(){
    int t; cin>>t;
    while(t--)  solve();
}