507 - Jill Rides Again

描述:求连续数列的最大和,如果存在和相等的,那么选取所跨区间大的,如果所跨区间一样大,则选取开始位置小的,结果因为输出时缺少一个字母“T”,结果wa那么多次……

#include <cstdio>

int num[20010];

int main()

{

   // freopen("a.txt","r",stdin);

    int n,m,count,sum,flag=1;

    scanf("%d",&n);

    while(n--)

    {

        scanf("%d",&m);

        count=0;

        sum=-1;

        int left,len=0,right;

        for(int i=0; i<m-1; i++)

        {

            scanf("%d",&num[i]);

            count+=num[i];

            if(count>sum)

            {

                sum=count;

                left=len+1;

                right=i+2;

            }

            else if(count==sum&&i+1-len>right-left)

            {

                right=i+2;

                left=len+1;

            }

            if(count<0)

            {

                count=0;

                len=i+1;

            }

        }

        if(sum<0) printf("Route %d has no nice parts\n",flag++);

        else printf("The nicest part of route %d is between stops %d and %d\n",flag++,left,right);

    }

    return 0;

}


你可能感兴趣的:(ide)