dp
代码:
#include<iostream>
#include<fstream>
using namespace std;
int n;
int l[50003],r[50003];
int a[50003];
void read(){
// ifstream cin("in.txt");
int i,j,k;
scanf("%d",&k);
while(k--)
{
scanf("%d",&n);
for(i=1;i<=n;i++)
{
scanf("%d",&a[i]);
}
for(i=1;i<=n;i++)
if(l[i-1]>0)
l[i]=a[i]+l[i-1];
else
l[i]=a[i];
int sum=-10000000;
for(i=1;i<=n;i++)
{
sum=max(sum,l[i]);
l[i]=sum;
}
r[n+1]=0;
for(i=n;i>=1;i--)
if(r[i+1]>0)
r[i]=a[i]+r[i+1];
else
r[i]=a[i];
sum=-10000000;
for(i=n;i>=1;i--)
{
sum=max(sum,r[i]);
r[i]=sum;
}
sum=-10000000;
for(i=1;i<n;i++)
sum=max(sum,l[i]+r[i+1]);
cout<<sum<<endl;
}
}
int main(){
read();
return 0;
}