I have been trying the problem WALK and codechef is telling that iam submitting a wrong answer. Can you correct my code.
#include<stdio.h>
#include<stdlib.h>
int main()
{
int i,N,T,max,test;
int imax;
int *W;
/*read the input
*find the number of test cases
*find the number of segments
*assign the segments their value
*/
scanf("%d",&N);
while(N--)
{
scanf("%d",&T);
W=(int *)malloc(T*sizeof(int));
for(i=0;i<T;i++)
{
scanf("%d",&W[i]);
}
/*find max*/
max=W[0];
imax=0;
for(i=1;i<T;i++)
{
if(W[i]>=max)
{
max=W[i];
imax=i;
}
//sum+=W[i];
}
test=max;
//test=(max+imax)*(imax+max+1)/2
//if(test>s)
for(i=imax;i<T;i++)
{
if(W[i]>test){max=max+W[i]-test;}
else test--;
}
printf("%d\n",max+imax);
}
return 0;
}