I am unable to understand my mistake in CARVANS …please help
#include<stdio.h>
int main()
{
int t,a[10000],r,y,f,i,n;
scanf("%d",&t);
for(i=0;i<t;i++)
{
f=1;
scanf("%d",&n);
for(y=0;y<n;y++)
scanf("%d",&a[y]);
for(r=0;r<n-1;r++)
{
if(a[r+1]<=a[r])
{
f++;
printf("%d",f);
}
else
a[r+1]=a[r];
}
printf("%d",f);
printf("\n");
}
return 0;
}
skr379
2
Your code is completely right, you are getting wrong answer because you are printing some extra lines.
You don’t have to print the value of f inside the loop, you have to print value of variable f just once outside the r loop for each test case.
I just commented that line of your code and submitted, it got accepted.
Here is the submission link http://www.codechef.com/submit/complete/288843-7424--54d28db6cd86f.