# Help for CLEANUP.

Problem :https://www.codechef.com/problems/CLEANUP
My solution : https://www.codechef.com/viewsolution/13174106

I found it, your code gives a weird output at test case-

``````Compilation Successful
Input (stdin)
1
1000 0

673 659 661 663 665 667 ...343(intentionally truncated. Note- The first number isn't even 1!!)
658 660 662 664 666 668 670 672 674 676 678 680 682 684 686 688 627 ...344
``````

I ran the same test case for another program and it gave me correct output. Your code shows unexpected behaviour when N=1000, even when m=1.

I have solved this question for you doing so much work of commenting to make you better understand the problem.Try to figure out where you are going wrong by comparing your solution with this. Try to figure out on your own, this would improve your debugging skills.

### Algorithm Used

• Make a vector of jobs from 1 to n (inclusive). say jobs[].
• Now while taking the inputs of the jobs that has been completed, just make that particular index of job equal to 0.
• now if job[i]==0, skip
• else, just change between the chef and assistant.

See the solution for better understanding. See My Solution Here

P.S

If still you are not able to understand/debug ping me out.

Please check my code : https://www.codechef.com/viewsolution/10296397

``````import java.io.*;
import java.util.Scanner;

class Job
{
int index;
boolean flag;

public void setIndex(int x)
{
index=x;
}
}

class CLEANUP
{
public static void main(String arg[])
{
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();

for(int i=0;i<t;i++)
{
int n=sc.nextInt();		int m=sc.nextInt();
Job job[]=new Job[n];

for(int j=0;j<n;j++)
{
job[j]=new Job();
job[j].setIndex(j+1);
}

int ind=0;
for(int j=0;j<m;j++)
{
int jobover=sc.nextInt();
for(int k=0;k<n;k++)
{
if(job[k].index==jobover)
{
ind=k;
break;
}
}
job[ind].flag=true;
}

Job temp[]=new Job[n-m];
int count=0;
for(int j=0;j<n;j++)
{
if(job[j].flag!=true)
{
temp[count]=job[j];
count++;
}
}

for(int j=0;j<n-m;j++)
{
for(int k=0;k<n-m-1;k++)
{
if(temp[k].index>temp[k+1].index)
{
Job swap=temp[k];
temp[k]=temp[k+1];
temp[k+1]=swap;
}
}
}

int noc=0,noa=0;
int chef[]=new int[n-m];
int assis[]=new int[n-m];

for(int j=0;j<n-m;j++)
{
if(j%2==0)
{
chef[noc]=temp[j].index;
noc++;
}
else
{
assis[noa]=temp[j].index;
noa++;
}
}

if(noc==0)
System.out.println();
else
{
for(int j=0;j<noc;j++)
System.out.print(chef[j]+" ");
System.out.println();
}

if(noa==0)
System.out.println();
else
{
for(int j=0;j<noa;j++)
System.out.print(assis[j]+" ");
System.out.println();
}

}

}
}``````

Fixed the format.