ALC002-code showing wrong answer on codechef

My code is working properly on my ide but when I try to submit it on codechef it is showing wrong answer

#include<stdio.h>
int main()
{
long int t,n,j,k,l,sum=0;
scanf("%ld",&t);
for(long int i=0;i<t;i++)
{
scanf("%d%d",&n,&k);
long int a[n];
for(long int j=0;j<n;j++)
scanf("%ld",&a[j]);
l=n;
while(l>=k)
{
long int b[(l/k)+(l%k)];
for( j=0;j<l/k;j++)
{
for(long int x=jk;x<(jk)+k;x++)
{
sum+=a[x];
}
b[j]=sum;
sum=0;
}
if((l%k)!=0)
{
for(j=0;j<l%k;j++)
{
b[l/k+j]=a[l-l%k+j];
}
}
l=(l/k)+(l%k);
for(j=0;j<l;j++)
a[j]=b[j];
}
for(j=0;j<l;j++)
printf("%ld “,a[j]);
printf(”\n");
}
return 0;
}

for(long int x=jk;x<(jk)+k;x++)

you should check this line in this your jk variable is undeclared.

That’s just an error introduced by the forum software because @kay_vee didn’t format their code :slight_smile:

Link to solution: https://www.codechef.com/viewsolution/26214494

I have no idea why this is failing as yet - it passes tons of randomised tests and doesn’t choke on the “large” testcases.

So what should I do now ?

Wait for someone smarter than me to come along :slight_smile:

Edit:

One thing that might be worth trying is to fix these warnings and re-submit:

kay_vee-ALC002.cpp:9:22: warning: format specifies type 'int *' but the argument has type 'long *' [-Wformat]
        scanf("%d%d",&n,&k);
               ~~    ^~
               %ld
kay_vee-ALC002.cpp:9:25: warning: format specifies type 'int *' but the argument has type 'long *' [-Wformat]
        scanf("%d%d",&n,&k);
                 ~~     ^~

(the line numbers might differ for you - I’ve made some local changes to your source).

@kay_vee

Edit2:

Yeah, it’s looking increasingly likely that the issue those warnings are complaining about is causing some nastiness - for example, changing the variable length arrays (shudder!) into vectors caused a crash if I didn’t fix those warnings, but worked fine when I did fix those warnings.

@ssjgz thanks alot for helping me out , it means a lot .
You were right by making those changes my code worked and codechef took my submission
Thanks a lot _/_

2 Likes

Awesome; glad to hear it :slight_smile:

2 Likes

@kay_vee What was this competition ALC? I participated in and solved two questions. is this a contest for a specific organization?

Actually it was a contest organized by PES University on 1st September from 21:00 to 2nd September 00:00 , i.e., 3 hours .
You had to pre-register for the contest and there were prizes for the winner .
There was nothing as such for a specific organization bro . Open to all . @aditya_81070

1 Like