#include
#include<math.h>
#include <bits/stdc++.h>
using namespace std;
int main()
{
int t,u=1;
cin>>t;
for(int k=0;k<t;k++)
{
int m,n;
cin>>n>>m;
int g=n-m,f=0;
int main[n];
int sub[m];
for(int i=0;i<m;i++)
{
cin>>sub[i];
}
// for(int i=0;i<m;i++)
// {
// cout<<sub[i];
// cout<<"\n";
// }
sort(sub,sub+m);
int e=0;
for(int l=0;l<n;l++)
{
if(l==sub[e])
{
main[l]=1;
e++;
}
if(main[l]!=1)
main[l]=0;
}
int rem[g];
for(int j=1;j<=n;j++)
{
if(main[j]!=1)
{
rem[f]=j;
f++;
// cout<<rem[f];
}
}
for(int p=0;p<(g);)
{
cout<<rem[p]<<" ";
p=p+2;
}
cout<<"\n";
for(int p=1;p<(g);)
{
cout<<rem[p]<<" ";
p=p+2;
}
// for(int p=1;p<g;)
// {
// cout<<rem[p];
// p=p+2;
// }
}
return 0;
}
ssjgz
August 24, 2021, 10:22am
2
Please either format your code or (better!) link to your submission - the forum software has mangled it and it won’t compile!
Also - which Problem are you trying to solve?
2 Likes
ssjgz
August 25, 2021, 11:01am
4
Thanks!
Consider the test input:
1
19 1
15
Also, some test inputs will create a zero-length dynamic array which is undefined behaviour, IIRC - might not be a problem, though.
1 Like
Thanks a lot,Ive fixed that but its still showing WA
https://www.codechef.com/viewsolution/50176668
ssjgz
August 25, 2021, 6:01pm
6
Hmmm … I’m not actually sure, then; it might be this:
Also, some test inputs will create a zero-length dynamic array which is undefined behaviour, IIRC - might not be a problem, though.
after all.
Edit:
Also try initialising sub
to all 0
s, or checking that e
has a valid value before checking if(l==sub[e])
.
Edit2:
Yeah, that’s probably it: without doing either of the above, the test input:
4
1 0
6 0
8 2
4 8
8 0
fairly reliably triggers an out-of-bounds access on my machine, though it relies on Undefined Behaviour so YMMV.
ssjgz
August 25, 2021, 6:36pm
8
I mean initialise the sub
array in your code so that it consists entirely of 0
s (before reading values into it).
Either of the following test inputs lead to 0-size arrays:
1
3 0
and
1
3 3
1 2 3
1 Like
it gives these out put on mine
6 0
1 3 5
2 4 6
1 0
1
8 2
4 8
1 3 6
2 5 7
8 0
1 3 5 7
2 4 6 8
Rest if u can give zero size dynamic array creator input , that would be really helpful , Thanks
well 3 3 didnt worked,output: no output
ssjgz
August 25, 2021, 6:48pm
10
Just try my suggestion and resubmit
Replace:
int sub[m];
with
int sub[m+1] = {};
and
int rem[g];
with
int rem[g+1];
1 Like
it worked and I dont know why
thanks a lot, I’ll try to figure out.