TRIP2 - Editorial

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() {
// your code goes here
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;

}

Your code is unformatted and wonā€™t compile - please either:

a) Link to your submission; or
b) Post it with formatting. Thanks! :slight_smile:

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

I can give you a failing testcase to help you debug :slight_smile:

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

1 Like

still a case pending corrected it.

I got 70, CodeChef: Practical coding for everyone

Now consider:

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

Link to latest submission?

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
Anyone please help me with the corner cases.

Hmmm ā€¦ small random testcases donā€™t seem to find any problems. Dunno, sorry :slight_smile:

No problemā€¦Thnx!!

1 Like

Ah - try this:

2
57 2
-1 -1 -1 -1 2 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 2 -1 
82 2
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 
  

Thatā€™s why I didnā€™t find it with randomised testcases - I always set T=1, whereas your issue only appears when there are multiple testcases. (Hint: thereā€™s some state left over from previous testcases that youā€™re not clearing :))

Consider:

1
1 9
-1 

Thanx bro for your timeā€¦finally submitted successfully!!!:v:

1 Like