ScratchCode PROB - Studds

I have solved the problem in the following way,

  1. Sort the boys and the girls vector(Vector of their heights)
  2. Insert the heights alternatively into a new vector of size (2*n) starting with whoever has the least height.

Here is my code snippet :slight_smile:

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define PRINT(x,y) cout<<"Case #"<<(int)x<<": "<<(int)(y)<<endl;
void solve() {
	int n; cin>>n;
	vector<int> b(n,0) , g(n,0);
	for(int i=0;i<n;++i) cin>>b[i];

	for(int i=0;i<n;++i) cin>>g[i];
	sort(b.begin() , b.end());
	sort(g.begin() , g.end());
	vector<int> c(2*n,0);
	if(b[0]<=g[0]) {
		int j = 0 ,m = 0;
		for(int i = 0;i<2*n;++i) {
			if(i%2==0) c[i] = b[m++];
			else c[i] = g[j++];
		}
	} else {
		int j = 0 , m = 0;
		for(int i = 0;i<2*n;++i) {
			if(i%2==0) c[i] = g[m++];
			else c[i] = b[j++];
		}
	}
	int sol = 0;
	for(int i = 0;i<2*n-1;++i) {
		if(c[i]>c[i+1]) {
			sol = 1; i = 2*n+5;
		}
	}
	if(sol==1) cout<<"NO\n";
	else cout<<"YES\n";
//	for(auto x:c) cout<<x<<" ";
}

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

I do not see where the error is, can someone be generous enough to look at it and give some valuable feedback as to where it crashed and gave WA verdict.
Thank you very much

try:
1
2
2 3
2 2

This should be a YES, 2 2 2 3 is possible where the starting ‘2’ is form the second list.
I got the error, thanks! There should be two checks, where I have only one.

yeah… you got it :+1: