题目: |
#include <iostream>
#include <cstring>
using namespace std;
int n,i,max1,j,h,t;
int a[10001],b[10001];
int main()
{
cin>>n;
b[0]=0;
for (i=1; i<=n; i++)
{
cin>>a[i];
b[i]=b[i-1]+a[i];
}
a[0]=0;
max1=-100;
for (i=1; i<=n; i++){
for (j=i; j<=n; j++){
b[j] -= a[i-1];
if (b[j]>max1){
h=i;
t=j;
max1=b[j];
}
}
}
if (max1<=0) cout<<0<<endl;
else cout<<max1<<endl;
return 0;
}
输入:
11
-2 11 -4 13 -50 -2 13 -1 3 6 -9 输出:21
|