Quantcast
Channel: CodeChef Discuss - latest questions
Viewing all articles
Browse latest Browse all 40121

Why am i getting wrong answer?

$
0
0

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;
}

Viewing all articles
Browse latest Browse all 40121

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>