In practice easy mode , CLEANUP problem (6 no from last ) my code is giving wrong answer
t = int(input())
while(t):
t=t-1
n,m= map(int,input().split())
tw =[i for i in range(1,n+1)]
l = list(map(int,input().split()))
rw=list(set(tw)-set(l))
print(*rw[0::2],sep =’ ')
print(*rw[1::2],sep = ’ ')

It works for sample input . But giving wrong answer answer. Can any one tell me?

Please either format your code or link to your submission - the forum software has stripped out the formatting and it won’t run!

t = int(input())
while(t):
t=t-1
n,m= map(int,input().split())
tw =[i for i in range(1,n+1)]
l = list(map(int,input().split()))
rw=list(set(tw)-set(l))
print(*rw[0::2],sep =’ ')
print(*rw[1::2],sep = ’ ')

tab below while(t) to all below rows

1 Like

Thanks - looks like you’re getting the wrong answer for the following testcase:

``````1
19 17
15 14 8 5 1 17 10 13 3 7 18 16 2 12 9 6 19
``````
1 Like

Thanks !, I think set change the order of element of “tw” thus giving wrong answer.
can it be better way to subtract 1st list to 2nd list without changing the order of element of 1st list ?

1 Like

In python sets are not sorted. So you need to sort the sets after performing subtraction. Link to my solution. I hope you will understand after seeing the solution.

1 Like

You are using `set` data-structure but you are not using the basic definition of the set i.e. A set is an unordered collection of distinct elements/objects.

Now when you performed the subtraction between the set `total_jobs_set - jobs_completed_set`, you are left with the set of `jobs` which are not completed, but the set is unordered, and as per the problem description, chef always chooses an even index job and his assistant always chooses an odd indexed job according to `zero-base indexing`, so you need to first sort the set to establish the order in the set and then use slice operator `[::]` to print the answer.

Below is a code for an AC solution for your reference.

``````def compute_the_assigned_jobs(jobs_set,jobs_completed_set):
jobs_uncompleted_set = jobs_set - jobs_completed_set
jobs_uncompleted_set = sorted(list(jobs_uncompleted_set))
print(' '.join(map(str,jobs_uncompleted_set[0::2])))
print(' '.join(map(str,jobs_uncompleted_set[1::2])))

def main():
for t in range(int(input().rstrip())):
n, m = tuple(map(int,input().rstrip().split()))
jobs_completed_set = set(map(int,input().rstrip().split()))
jobs_set = set([i for i in range(1,n + 1)])
compute_the_assigned_jobs(jobs_set,jobs_completed_set)

if __name__ == "__main__":
main()
``````
Test-Cases
``````Input:
4
6 3
2 4 1
3 2
3 2
8 2
3 8
19 17
15 14 8 5 1 17 10 13 3 7 18 16 2 12 9 6 19

Output:
3 6
5
1

1 4 6
2 5 7
4
11
``````

Peace

1 Like

Why is this CLEANUP solution code giving wrong answers ?

#include
using namespace std;
int main()
{
int t,n,m,temp;
cin >> t;
while(t–)
{
cin >> n >> m;
int job[n];
for(int i = 0;i < n;i++)
{
job[i] = i + 1;
}
for(int i = 1;i <= m;i++)
{
cin >> temp;
job[temp-1] = 0;
}
int least_index,least_index2;
for(int i = 0; i < n;i++)
{
if(job[i])
{
least_index = i;
break;
}
}
for(int i = least_index + 1;i < n;i++)
{
if(job[i])
{
least_index2 = i;
break;
}
}
int k = 1,l = 2;
for(int i = least_index;i < n;i++)
{
if(job[i] && (k % 2 == 1))
{
cout << job[i] << " ";
k++;
}
else if(job[i])
{
k++;
}
}
cout << “\n”;
for(int i = least_index2;i < n;i++)
{
if(job[i] && (l % 2 == 0))
{
cout << job[i] << " ";
l++;
}
else if(job[i])
{
l++;
}
}
cout << “\n”;
}
}

Thanks You’re not initialising `least_index` nor`least_index2`, so the output is undefined.

But i am initialising them inside the for loops finding the minimum indices for chef and assistant. Also the test cases given are working fine.

`least_index2` (at least) is not initialised during the testcase:

``````1
3 2
3 2
``````

There’s Undefined Behaviour for you

1 Like

Oh yes. You are right. I corrected it and got my green tick. Thanks a lot.

1 Like