| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
大神帮忙看看 超时了#include<iostream>
#include<cstdio>
#define max 50000
using namespace std;
int maxsum(int *a,int head,int tail)
{
int sum=-999999;
int b=0;
for(int i=head;i<=tail;i++)
{
if(b>0) b+=a[i];
else b=a[i];
if(b>sum) sum=b;
}
return sum;
}
int main()
{
int n;
int T;
int a[max+1];
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%d",a+i);
int sum=-999999999;
int result;
for(int i=1;i<=n;i++)
{
result=maxsum(a,1,i)+maxsum(a,i+1,n);
if(result>=sum)
{
sum=result;
}
}
printf("%d\n",sum);
}
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator