pat甲级1007

有两个测试点没过

#include <iostream>
#include<cstdio>
#include<algorithm>

using namespace std;
const int maxn=10010;

int main()
{
    int a[maxn];
    int thismaxn=0;
    int zuida=0;
    int number;
    int first,last;
    cin>>number;
    for(int i=0;i<number;i++)
    {
        cin>>a[i];
    }
    for(int i=0;i<number;i++)
    {
        thismaxn=0;
        for(int j=i;j<number;j++)
        {
            thismaxn +=a[j];
            if(thismaxn>zuida)
            {
                zuida =thismaxn;
                first=i;
                last =j;
            }
        }
    }
    printf("%d %d %d",zuida,a[first],a[last]);

    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_37802644/article/details/79490412