CLEANUP wrong ans

getin right output wid all test cases providd by the question bt stil showing wrong ans cant figure out y …the question is CLEANUP

#include<iostream>
#include<stdio.h>

void swap(int &a,int &b)
{
int temp;
temp=a;
a=b;
b=temp;
}
void sort(int a[],int n)
{
int i,j;
for(i=0;i<n-1;i++)
    for(j=i;j<n;j++)                       //first 2 func are sortng array wid "m" elements
{
    if(a[i]>a[j])
        swap(a[i],a[j]);
}
}
int main()
{
int t,n,m,a[1000],b[1000],c[500],d[500],temp,k,j,l,i;
scanf("%d",&t);
while(t--)
{
    j=k=l=temp=0;
    scanf("%d %d",&n,&m);
    for(i=0;i<n;i++)
        a[i]=i+1;
    for(i=0;i<m;i++)
        scanf("%d",&b[i]);
    sort(b,m);
    for(i=0;i<n;i++)
    {

        if(temp%2==0 && b[j]!=a[i])
        {
            c[k]=a[i];
            k++;
            temp++;
        }else
        if(temp%2!=0 && b[j]!=a[i])
        {
            d[l]=a[i];
            l++;
            temp++;
        }else
        if(b[j]==a[i])
        {
            j++;
        }

    }
        for(i=0;i<k;i++)
            printf("%d ",c[i]);
        printf("\n");
        for(i=0;i<l;i++)
            printf("%d ",d[i]);
            printf("\n");


}

}