Why doesn't the following code for CLEANUP work?

cleanup
doubt

#1
#include
#include
#include
using namespace std;
int main()
{
	int t;
	cin >> t;
	while(t--)
	{
		int num_job, job_com;
		cin >> num_job >> job_com;
		vector j;
		int k;
		for(int i = 0; i < job_com; i++)
		{
			cin >> k;
			j.push_back(k);
		}
		if(num_job == job_com)
		{
			cout << endl;
			cout << endl;
		}
		else
		{
		sort(j.begin(), j.end());
		bool m = true;
		vector chef;
		vector ass;
		int l = 1;
		int i = 1;
		while(l<=num_job - job_com)
		{
			while(m == true && l <= num_job - job_com)
			{
				if(i == j[0])
				{
					i = i + 1;
					j.erase(j.begin());
				}
				else if(i != j[0])
				{
					  chef.push_back(i);
					  i = i + 1;
					  m = false;
					  l = l + 1;
			    }
			}
			while(m == false && l <= num_job - job_com)
			{
				if(i == j[0])
				{
					i = i + 1;
					j.erase(j.begin());
				}
				else if(i != j[0])
				{
					  ass.push_back(i);
					  i = i + 1;
					  m = true;
					  l = l + 1;
			    }
			}
		}
		int yo = chef.size();
		int oy = ass.size();
		for(int c = 0; c < 	yo; c ++)
		{
			cout << chef[c] << " ";
		}
		cout << endl;
		if(oy != 0)
		{
		for(int c = 0; c < oy; c ++)
		{
			cout << ass[c] << " ";
		}
		cout << endl;
		}
		else
		{
		cout << endl;
	    }
	}	   
	}
	return 0;
}

It works fine on my machine, but when I submit it, I get an SIGSEGV error.


#2

Hi

This is an error caused by an invalid memory reference or segmentation fault. The most common causes are accessing an vector element out of bounds, or using too much memory.

Some things for you to try:

Make sure you aren’t using variables that haven’t been initialized. These may be set to 0 on your computer, but aren’t guaranteed to be on the judge.

Check every single occurrence of accessing an vector element and see if it could possibly be out of bounds.

Hope this helps.