Consider:
1
8 2
-1 2 -1 -1 -1 2 -1 -1
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!
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
1
7 2
-1 -1 1 -1 -1 -1 -1
still a case pending corrected it.
Now consider:
1
6 2
2 1 -1 -1 1 2
Link to latest submission?
Thank you. Figured it out.
Hmmm ā¦ small random testcases donāt seem to find any problems. Dunno, sorry
No problemā¦Thnx!!
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!!!