# TRIP2 - Editorial

Plz check why my code is wrong
problem code TRIP2

#include
using namespace std;

long int check( long int a[] ,long int k , long int n )
{
long int j;
long int q=a[1];
if(n==1)
{
return k;
}
for(j=1;j<=k;j++)
{
if(j!=q)
break;
}
return j;
}

long int ch(long int a[] , long int k , long int i)
{
long int j;
for(j=1;j<=k;j++)
{
if(j!=a[i-1] && j!=a[i+1])
break;
}
return j;

}

long int chh(long int a[] , long int k , long int n)
{
long int j;
for(j=1;j<=k;j++)
{
if(j!=a[n-2])
break;
}
return j;

}

int main() {
int t;
cin>>t;
while(t–)
{
long int n,k;
cin>>n>>k;
long int a[n],i;
for(i=0;i<n;i++)
{
cin>>a[i];

``````    }
for(i=0;i<n;i++)
{
if(a[0]==-1) a[0]=check(a , k , n);
else if(i>0 && i<n-1 && a[i]==-1)            a[i]=ch(a , k , i);

else if(a[n-1]==-1)                       a[n-1]=chh(a , k , n);
}

for(i=0;i<n;i++)
{
if(n==1) i=1;
else if(a[i]==a[i+1] || a[i]==k+1 )
break;
}
if(i!=n)
{
cout<<"NO"<<endl;
}
else {
cout<<"YES"<<endl;
for(i=0;i<n;i++)
cout<<a[i]<<"\t";
cout<<endl;
}

}
return 0;
``````

}

can someone please give a case for which my code isn’t working.
https://www.codechef.com/viewsolution/26195971

Here’s my solution, by the way - hopefully more readable than the Editorial ones

https://www.codechef.com/viewsolution/26197441

Consider:

``````1
8 2
-1 2 -1 -1 -1 2 -1 -1
``````

Can anyone plz help me here. My code runs well for the input Sample but it is giving me wrong answer when i submit it. Below is my code for the same.

#include
using namespace std;

int main() {
int t,i;
cin >> t;
for(i=0;i<t;i++)
{
int n,k;
cin >> n >> k;
int a[n];
for(int j=0;j<n;j++)
{
cin >> a[j];
}
int z=1;

``````    for(int j=0;j<n;j++)
{
int h;
if(a[j]==-1 )
{
h=z;
if(h>k)
h=z%k;
a[j]=h;
z++;
}

}
int u=0;
for(int j=0;j<n;j++)
{
if(a[j]==a[j+1]){
cout << "NO\n";

u=1;
break;
}
}
if(u!=1)
{
cout << "YES\n";
for(int j=0;j<n;j++)
{
cout << a[j] <<" ";
}
cout << "\n";
}
}
return 0;
``````

}

b) Post it with formatting. Thanks!

Edit:

Got it to compile - consider the testcase:

``````1
6 4
1 -1 -1 -1 2 -1
``````

ya corrected it but still getting just 70.
any other test case.
https://www.codechef.com/viewsolution/26196801

Consider:

``````1
5 2
-1 -1 -1 -1 -1
``````

Hi, can you also tell where is my going wrong? Sorry, I am newbie here.
https://www.codechef.com/viewsolution/26196831

``````1
7 2
-1 -1 1 -1 -1 -1 -1

``````
1 Like

still a case pending corrected it.

Now consider:

``````1
6 2
2 1 -1 -1 1 2
``````
1 Like

https://www.codechef.com/viewsolution/26197173

https://www.codechef.com/viewsolution/26197173
Latest submission

Thank you. Figured it out.

1 Like

https://www.codechef.com/viewsolution/26178967