ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2060D - Subtract Min Sort
Language: C++20 (GCC 13-64)

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



using namespace std;



#define f first

#define s second

#define pb push_back

#define all(x) x.begin(), x.end()

#define sz(x) (int)x.size()

#define mp make_pair

typedef long long ll;

typedef pair<int, int> ii;

typedef vector<int> vi;

typedef vector<ii> vii;

const int MAX = 1e5 + 5;

const int MOD = 1e9 + 7;

const int INF = 1e9;

const ll LLINF = 1e18;

const double EPS = 1e-9;



ll n, m, k, t;

string s1, s2;

vi v;

int gcd(int a, int b) { return b == 0? a: gcd(b, a % b); }





int main() {

    ios::sync_with_stdio(false); cin.tie(NULL);



    int t; cin >> t;

    while(t--) {

      cin >> n;

      vi a(n);

      for (int& c: a) cin >> c;

      // v.resize(n);

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

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

          if (i == 0) {

            cout << "NO";

            goto next;

          } else {

            int m= min(a[i - 1], a[i]);

            a[i] -= m;

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

              cout << "NO";

              goto next;

            }

          }

        }

      }

      cout << "YES";

      next:;

      cout << "\n";

    }



    return 0;

}

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



using namespace std;



#define f first

#define s second

#define pb push_back

#define all(x) x.begin(), x.end()

#define sz(x) (int)x.size()

#define mp make_pair

typedef long long ll;

typedef pair<int, int> ii;

typedef vector<int> vi;

typedef vector<ii> vii;

const int MAX = 1e5 + 5;

const int MOD = 1e9 + 7;

const int INF = 1e9;

const ll LLINF = 1e18;

const double EPS = 1e-9;



ll n, m, k, t;

string s1, s2;

vi v;

int gcd(int a, int b) { return b == 0? a: gcd(b, a % b); }





int main() {

    ios::sync_with_stdio(false); cin.tie(NULL);



    int t; cin >> t;

    while(t--) {

      cin >> n;

      vi a(n);

      for (int& c: a) cin >> c;

      // v.resize(n);

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

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

          if (i == 0) {

            cout << "NO";

            goto next;

          } else {

            int m= min(a[i - 1], a[i]);

            a[i] -= m;

            a[i - 1] -= m;

            if (a[i] > a[i + 1] || (i - 1 > 0 && a[i - 1] > a[i])) {

              cout << "NO";

              goto next;

            }

          }

        }

      }

      cout << "YES";

      next:;

      cout << "\n";

    }



    return 0;

}
Problem: 2060D - Subtract Min Sort
Language: C++20 (GCC 13-64)


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



using namespace std;



#define f first

#define s second

#define pb push_back

#define all(x) x.begin(), x.end()

#define sz(x) (int)x.size()

#define mp make_pair

typedef long long ll;

typedef pair<int, int> ii;

typedef vector<int> vi;

typedef vector<ii> vii;

const int MAX = 1e5 + 5;

const int MOD = 1e9 + 7;

const int INF = 1e9;

const ll LLINF = 1e18;

const double EPS = 1e-9;



ll n, m, k, t;

string s1, s2;

vi v;

int gcd(int a, int b) { return b == 0? a: gcd(b, a % b); }





int main() {

    ios::sync_with_stdio(false); cin.tie(NULL);



    int t; cin >> t;

    while(t--) {

      cin >> n;

      vi a(n);

      for (int& c: a) cin >> c;

      // v.resize(n);

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

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

          if (i == 0) {

            cout << "NO";

            goto next;

          } else {

            int m= min(a[i - 1], a[i]);

            a[i] -= m;

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

              cout << "NO";

              goto next;

            }

          }

        }

      }

      cout << "YES";

      next:;

      cout << "\n";

    }



    return 0;

}
Problem: 2057B - Gorilla and the Exam
Language: C++17 (GCC 7-32)

Previous submission (verdict: Time limit exceeded on test 14):
#include <bits/stdc++.h>
#include <cassert>

#define endl "\n"
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef double lld;

using vi = vector<int>;
using pii = pair<int, int>;
using vii = vector<vector<int>>;

#define endl "\n"
#define all(x) (x).begin(),  (x).end()
#define inf 1e9


 
const int mod = (int)1e9 + 7;

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

	vector<int> arr(n);

	unordered_map<int, int> freq;

	for(int i = 0; i < n; i++){
		cin >> arr[i];
		freq[arr[i]]++;
	}

	priority_queue<pii, vector<pii>, greater<pii>> pq;

	int maxval = INT_MIN, storemax;
	for(auto it: freq){
		pq.push(make_pair(it.second, it.first));
		if(maxval < it.second){
			maxval = it.second;
			storemax = it.first;
		}
	}

	pii store = make_pair(INT_MAX, INT_MAX);
	int soln = 0;

	while(k > 0 && pq.empty() == false){
		int val = pq.top().second;
		int fr = pq.top().first;
		pq.pop();
		if(fr > 0 && val != storemax){
			pq.push(make_pair(fr-1, val));
			k--;
		}
		else if(storemax == val){
			store = make_pair(fr, val);
		}
	}

	if(!(store.first == INT_MAX && store.second == INT_MAX)){
		pq.push(store);
	}

	

	while(pq.empty()==false){
		if(pq.top().first != 0){
			soln++;
		}
		pq.pop();
	}

	cout << soln << endl;

}

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

	int t = 1;
	cin >> t;

	while(t--){
		solve();
	}
	

	return 0;	
}

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

#define endl "\n"
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef double lld;

using vi = vector<int>;
using pii = pair<int, int>;
using vii = vector<vector<int>>;

#define endl "\n"
#define all(x) (x).begin(),  (x).end()
#define inf 1e9


 
const int mod = (int)1e9 + 7;

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

	vector<int> arr(n);

	unordered_map<int, int> freq;
	unordered_set<int> s;
	for(int i = 0; i < n; i++){
		cin >> arr[i];
		freq[arr[i]]++;
		s.insert(arr[i]);
	}

	priority_queue<pii, vector<pii>, greater<pii>> pq;

	int maxval = INT_MIN, storemax;
	for(auto it: freq){
		pq.push(make_pair(it.second, it.first));
		if(maxval < it.second){
			maxval = it.second;
			storemax = it.first;
		}
	}

	pii store = make_pair(INT_MAX, INT_MAX);
	int soln = 0;

	while(k > 0 && pq.empty() == false){
		int val = pq.top().second;
		int fr = pq.top().first;
		pq.pop();
		if(fr > 0 && val != storemax){
			if((fr-1) == 0){
				s.erase(val);
			}
			else pq.push(make_pair(fr-1, val));
			k--;
		}
	}



	cout << s.size() << endl;

}

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

	int t = 1;
	cin >> t;

	while(t--){
		solve();
	}
	

	return 0;	
}
Problem: 2057B - Gorilla and the Exam
Language: C++17 (GCC 7-32)

Previous submission (verdict: Time limit exceeded on test 14):
#include <bits/stdc++.h>
#include <cassert>

#define endl "\n"
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef double lld;

using vi = vector<int>;
using pii = pair<int, int>;
using vii = vector<vector<int>>;

#define endl "\n"
#define all(x) (x).begin(),  (x).end()
#define inf 1e9


 
const int mod = (int)1e9 + 7;

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

	vector<int> arr(n);

	unordered_map<int, int> freq;
	unordered_set<int> s;
	for(int i = 0; i < n; i++){
		cin >> arr[i];
		freq[arr[i]]++;
		s.insert(arr[i]);
	}

	priority_queue<pii, vector<pii>, greater<pii>> pq;

	int maxval = INT_MIN, storemax;
	for(auto it: freq){
		pq.push(make_pair(it.second, it.first));
		if(maxval < it.second){
			maxval = it.second;
			storemax = it.first;
		}
	}

	pii store = make_pair(INT_MAX, INT_MAX);
	int soln = 0;

	while(k > 0 && pq.empty() == false){
		int val = pq.top().second;
		int fr = pq.top().first;
		pq.pop();
		if(fr > 0 && val != storemax){
			if((fr-1) == 0){
				s.erase(val);
			}
			else pq.push(make_pair(fr-1, val));
			k--;
		}
	}



	cout << s.size() << endl;

}

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

	int t = 1;
	cin >> t;

	while(t--){
		solve();
	}
	

	return 0;	
}

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

#define endl "\n"
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef double lld;

using vi = vector<int>;
using pii = pair<int, int>;
using vii = vector<vector<int>>;

#define endl "\n"
#define all(x) (x).begin(),  (x).end()
#define inf 1e9


 
const int mod = (int)1e9 + 7;

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

	vector<int> arr(n);

	unordered_map<int, int> freq;
	unordered_set<int> s;
	for(int i = 0; i < n; i++){
		cin >> arr[i];
		freq[arr[i]]++;
		s.insert(arr[i]);
	}

	priority_queue<pii, vector<pii>, greater<pii>> pq;

	int maxval = INT_MIN, storemax;
	for(auto it: freq){
		pq.push(make_pair(it.second, it.first));
		if(maxval < it.second){
			maxval = it.second;
			storemax = it.first;
		}
	}

	pii store = make_pair(INT_MAX, INT_MAX);
	int soln = 0;

	while(k > 0 && pq.empty() == false){
		int val = pq.top().second;
		int fr = pq.top().first;
		pq.pop();
		if(fr > 0 && val != storemax){
			int low = fr > k ? k : fr;
			if((fr-low) <= 0){
				s.erase(val);
			}
			k-=low;
		}
	}



	cout << s.size() << endl;

}

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

	int t = 1;
	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>
#include <cassert>

#define endl "\n"
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef double lld;

using vi = vector<int>;
using pii = pair<int, int>;
using vii = vector<vector<int>>;

#define endl "\n"
#define all(x) (x).begin(),  (x).end()
#define inf 1e9


 
const int mod = (int)1e9 + 7;

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

	vector<int> arr(n);

	unordered_map<int, int> freq;

	for(int i = 0; i < n; i++){
		cin >> arr[i];
		freq[arr[i]]++;
	}

	priority_queue<pii, vector<pii>, greater<pii>> pq;

	int maxval = INT_MIN, storemax;
	for(auto it: freq){
		pq.push(make_pair(it.second, it.first));
		if(maxval < it.second){
			maxval = it.second;
			storemax = it.first;
		}
	}

	pii store = make_pair(INT_MAX, INT_MAX);
	int soln = 0;

	while(k > 0 && pq.empty() == false){
		int val = pq.top().second;
		int fr = pq.top().first;
		pq.pop();
		if(fr > 0 && val != storemax){
			pq.push(make_pair(fr-1, val));
			k--;
		}
		else if(storemax == val){
			store = make_pair(fr, val);
		}
	}

	if(!(store.first == INT_MAX && store.second == INT_MAX)){
		pq.push(store);
	}

	

	while(pq.empty()==false){
		if(pq.top().first != 0){
			soln++;
		}
		pq.pop();
	}

	cout << soln << endl;

}

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

	int t = 1;
	cin >> t;

	while(t--){
		solve();
	}
	

	return 0;	
}
Problem: 2057B - Gorilla and the Exam
Language: C++17 (GCC 7-32)

Previous submission (verdict: Time limit exceeded on test 14):
#include <bits/stdc++.h>
#include <cassert>

#define endl "\n"
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef double lld;

using vi = vector<int>;
using pii = pair<int, int>;
using vii = vector<vector<int>>;

#define endl "\n"
#define all(x) (x).begin(),  (x).end()
#define inf 1e9


 
const int mod = (int)1e9 + 7;

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

	vector<int> arr(n);

	unordered_map<int, int> freq;

	for(int i = 0; i < n; i++){
		cin >> arr[i];
		freq[arr[i]]++;
	}

	vi arr1;

	for(auto it: freq){
		arr1.push_back(it.second);
	}

	sort(arr1.begin(), arr1.end());

	int m = arr1.size();
	int fl = 0;

	for(int i = 0; i < m-1; i++){
		if(arr1[i] > k){
			cout << m - i << endl;
			return;
		}
		k -= arr1[i];
	}
	cout << 1 << endl;

}

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

	int t = 1;
	cin >> t;

	while(t--){
		solve();
	}
	

	return 0;	
}

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

#define endl "\n"
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef double lld;

using vi = vector<int>;
using pii = pair<int, int>;
using vii = vector<vector<int>>;

#define endl "\n"
#define all(x) (x).begin(),  (x).end()
#define inf 1e9


 
const int mod = (int)1e9 + 7;

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

	vector<int> arr(n);


	for(int i = 0; i < n; i++){
		cin >> arr[i];
	}

	sort(arr.begin(), arr.end());
	vi arr1;
	int cnt = 1;

	for(int i = 1; i < n; i++){
		if(arr[i] == arr[i-1]){
			cnt++;
		}
		else{
			arr1.emplace_back(cnt);
			cnt = 1;
		}
	}
	arr1.emplace_back(cnt);

	sort(arr1.begin(), arr1.end());

	int m = arr1.size();

	for(int i = 0; i < m-1; i++){
		if(arr1[i] > k){
			cout << m - i << endl;
			return;
		}
		k -= arr1[i];
	}
	cout << 1 << endl;

}

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

	int t = 1;
	cin >> t;

	while(t--){
		solve();
	}
	

	return 0;	
}
Problem: 2057B - Gorilla and the Exam
Language: C++17 (GCC 7-32)

Previous submission (verdict: Time limit exceeded on test 14):
#include <bits/stdc++.h>
#include <cassert>

#define endl "\n"
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef double lld;

using vi = vector<int>;
using pii = pair<int, int>;
using vii = vector<vector<int>>;

#define endl "\n"
#define all(x) (x).begin(),  (x).end()
#define inf 1e9


 
const int mod = (int)1e9 + 7;

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

	vector<int> arr(n);

	unordered_map<int, int> freq;
	unordered_set<int> s;
	for(int i = 0; i < n; i++){
		cin >> arr[i];
		freq[arr[i]]++;
		s.insert(arr[i]);
	}

	priority_queue<pii, vector<pii>, greater<pii>> pq;

	int maxval = INT_MIN, storemax;
	for(auto it: freq){
		pq.push(make_pair(it.second, it.first));
		if(maxval < it.second){
			maxval = it.second;
			storemax = it.first;
		}
	}

	pii store = make_pair(INT_MAX, INT_MAX);
	int soln = 0;

	while(k > 0 && pq.empty() == false){
		int val = pq.top().second;
		int fr = pq.top().first;
		pq.pop();
		if(fr > 0 && val != storemax){
			int low = fr > k ? k : fr;
			if((fr-low) <= 0){
				s.erase(val);
			}
			k-=low;
		}
	}



	cout << s.size() << endl;

}

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

	int t = 1;
	cin >> t;

	while(t--){
		solve();
	}
	

	return 0;	
}

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

#define endl "\n"
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef double lld;

using vi = vector<int>;
using pii = pair<int, int>;
using vii = vector<vector<int>>;

#define endl "\n"
#define all(x) (x).begin(),  (x).end()
#define inf 1e9


 
const int mod = (int)1e9 + 7;

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

	vector<int> arr(n);

	unordered_map<int, int> freq;

	for(int i = 0; i < n; i++){
		cin >> arr[i];
		freq[arr[i]]++;
	}

	vi arr1;

	for(auto it: freq){
		arr1.push_back(it.second);
	}

	sort(arr1.begin(), arr1.end());

	int m = arr1.size();
	int fl = 0;

	for(int i = 0; i < m-1; i++){
		if(arr1[i] > k){
			cout << m - i << endl;
			return;
		}
		k -= arr1[i];
	}
	cout << 1 << endl;

}

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

	int t = 1;
	cin >> t;

	while(t--){
		solve();
	}
	

	return 0;	
}
Problem: 2063B - Subsequence Update
Language: C++17 (GCC 7-32)

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

using namespace std;

const int N = 100005;

int a[N];

void solve(){

	int n,l,r;

	cin >> n >> l >> r;

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

		cin >> a[i];

	sort(a + l,a + 1 + r,greater<int>());

	sort(a + 1,a + l),sort(a + r,a + 1 + n);

	long long ans1 = 0,ans2 = 0;

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

		if(i - l + 1 < l && a[i - l + 1] < a[i])

			ans1 += a[i - l + 1];

		else

			ans1 += a[i];

		if(r + i - l + 1 <= n && a[r + i - l + 1] < a[i])

			ans2 += a[r + i - l + 1];

		else

			ans2 += a[i];

	}

	cout << min(ans1,ans2) << '\n';

}

int main(){

	cin.tie(0);

	ios::sync_with_stdio(0);

	int T;cin >> T;

	while(T--)solve();

	return 0;

}



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

using namespace std;

const int N = 100005;

int a[N];

void solve(){

	int n,l,r;

	cin >> n >> l >> r;

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

		cin >> a[i];

	sort(a + l,a + 1 + r,greater<int>());

	sort(a + 1,a + l),sort(a + 1 + r,a + 1 + n);

	long long ans1 = 0,ans2 = 0;

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

		int p = i - l + 1;

		if(p < l && a[p] < a[i])ans1 += a[p];

		else ans1 += a[i];

		int q = r + i - l + 1;

		if(q <= n && a[q] < a[i])ans2 += a[q];

		else ans2 += a[i];

	}

	cout << min(ans1,ans2) << '\n';

}

int main(){

	cin.tie(0);

	ios::sync_with_stdio(0);

	int T;cin >> T;

	while(T--)solve();

	return 0;

}
Problem: 2063B - Subsequence Update
Language: C++17 (GCC 7-32)


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

using namespace std;

const int N = 100005;

int a[N];

void solve(){

	int n,l,r;

	cin >> n >> l >> r;

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

		cin >> a[i];

	sort(a + l,a + 1 + r,greater<int>());

	sort(a + 1,a + 1 + l);

	sort(a + r,a + 1 + n);

	long long ans1 = 0,ans2 = 0;

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

		if(i - l + 1 < l && a[i - l + 1] < a[i])

			ans1 += a[i - l + 1];

		else

			ans1 += a[i];

		if(r + i - l + 1 <= n && a[r + i - l + 1] < a[i])

			ans2 += a[r + i - l + 1];

		else

			ans2 += a[i];

	}

	cout << min(ans1,ans2) << '\n';

}

int main(){

	cin.tie(0);

	ios::sync_with_stdio(0);

	int T;cin >> T;

	while(T--)solve();

	return 0;

}
Problem: 2063B - Subsequence Update
Language: C++17 (GCC 7-32)

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

using namespace std;

const int N = 100005;

int a[N];

void solve(){

	int n,l,r;

	cin >> n >> l >> r;

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

		cin >> a[i];

	sort(a + l,a + 1 + r,greater<int>());

	sort(a + 1,a + 1 + l);

	sort(a + r,a + 1 + n);

	long long ans1 = 0,ans2 = 0;

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

		if(i - l + 1 < l && a[i - l + 1] < a[i])

			ans1 += a[i - l + 1];

		else

			ans1 += a[i];

		if(r + i - l + 1 <= n && a[r + i - l + 1] < a[i])

			ans2 += a[r + i - l + 1];

		else

			ans2 += a[i];

	}

	cout << min(ans1,ans2) << '\n';

}

int main(){

	cin.tie(0);

	ios::sync_with_stdio(0);

	int T;cin >> T;

	while(T--)solve();

	return 0;

}



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

using namespace std;

const int N = 100005;

int a[N];

void solve(){

	int n,l,r;

	cin >> n >> l >> r;

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

		cin >> a[i];

	sort(a + l,a + 1 + r,greater<int>());

	sort(a + 1,a + l),sort(a + r,a + 1 + n);

	long long ans1 = 0,ans2 = 0;

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

		if(i - l + 1 < l && a[i - l + 1] < a[i])

			ans1 += a[i - l + 1];

		else

			ans1 += a[i];

		if(r + i - l + 1 <= n && a[r + i - l + 1] < a[i])

			ans2 += a[r + i - l + 1];

		else

			ans2 += a[i];

	}

	cout << min(ans1,ans2) << '\n';

}

int main(){

	cin.tie(0);

	ios::sync_with_stdio(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 6):
#include <bits/stdc++.h>



using namespace std;

typedef long long ll;

typedef array<int, 3> triple;

const ll INF = 0x3f3f3f3f3f3f3f3f;



#define MAXLEN 100001

#define min(a, b) ((a) < (b) ? (a) : (b))

#define max(a, b) ((a) > (b) ? (a) : (b))

#define mod(a, b) ((long long) ((a) - (b)*floor((long double) (a)/(b))))

#define FIXIO  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);



#define vi vector<int>

#define vll vector<ll>

#define vpi vector<pair<int,int>>

#define all(v) v.begin(), v.end()

#define rall(v) v.rbegin(), v.rend()

#define pre(r, l) for (ll i = (r); i >= ll((l)); i--)

#define fro(l, r) for (ll i = (l); i <= ll((r)); i++)





void solve() {

    ll n, m;

    cin >> n >> m;

    vector<int> A(n), B(m);

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

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



    map<int, int> freqA, freqB;

    for (auto &i: A) freqA[i]++;

    for (auto &i: B) freqB[i]++;



    priority_queue<int> q;

    for (auto &i: freqB) {

        if (i.second > freqA[i.first]) {

            q.push(i.first);

        }

    }



    while (!q.empty()) {

        int curr = q.top(); q.pop();

        if (curr == 1) {

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

            return;

        }

        

        int divs = freqB[curr]-freqA[curr];

        freqB[curr] -= divs;

        freqB[curr/2] += divs;

        freqB[(curr+1)/2] += divs;



        if (freqB[curr/2] > freqA[curr/2])

            q.push(curr/2);

        if (curr/2 != (curr+1)/2)

            if (freqB[(curr+1)/2] > freqA[(curr+1)/2])

                q.push((curr+1)/2);

    }



    for (auto &i: freqB) {

        // cout << i.first << ':' << i.second << ' ';

        if (i.second != freqA[i.first]) {

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

            return;

        }

    }

    // cout << '\n';



    for (auto &i: freqA) {

        // cout << i.first << ':' << i.second << ' ';

        if (i.second != freqB[i.first]) {

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

            return;

        }

    }

    // cout << '\n';



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



}





int main() {

    FIXIO;



    ll t;

    t = 1;

    cin >> t;



    while (t--) {

        solve();

    }



    return 0;

}
Problem: 2062C - Cirno and Operations
Language: C++17 (GCC 7-32)


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

void solve_1() {
    int n;
    cin >> n;
    vector<string> g(n);

    for (int i = 0; i < n; ++i) {
        cin >> g[i];
    }

    vector<int> p(n, LONG_LONG_MAX);
    for (int i = 0; i < n; ++i) {
        for (int j = i + 1; j < n; ++j) {
            if (g[i][j] == '0') {
                p[j] = i;
            } else {
                if (p[i] > j) {
                    p[i] = j;
                }
            }
        }
        cout << "p: "; for (int b : p) cout << b << ' '; cout << '\n';
    }

    int mex = 0;
    vector<bool> f(n + 1);
    for (int i = 0; i < n; ++i) {
        if (p[i] < n) {
            f[p[i]] = true;
        }
    }

    for (int i = 0; i <= n; ++i) {
        if (!f[i]) {
            mex = i;
            break;
        }
    }

    cout << "f: "; for (bool b : f) cout << b << ' '; cout << '\n';
    cout << "p: "; for (int b : p) cout << b << ' '; cout << '\n';

    int t = mex;
    while (t != LONG_LONG_MAX) {
        cout << t << ' ';
        t = p[t];
    }
    cout << '\n';
}

void printIntVec(vector<int> &v, string name) {
    cout << name << ": ";
    for (int i : v) cout << i << ' ';
    cout << '\n';
}

void inIntVec(vector<int> &v) {
    for (int i = 0; i < v.size(); ++i) {
        cin >> v[i];
    }
}

void solve() {
    int n;
    cin >> n;
    vector<int> a(n);
    inIntVec(a);
    int mx = accumulate(a.begin(), a.end(), 0);
    if (a.size() == 1) {
        cout << mx << '\n';
        return;
    }
    while (a.size() > 1) {
        vector<int> tmp;
        for (int i = 1; i < a.size(); ++i) {
            tmp.push_back(a[i] - a[i - 1]);
        }
        a = tmp;
    }
    cout << max(mx, abs(a[0])) << '\n';
}

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