标签:des blog http io ar os sp for strong
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 34180 | Accepted: 10588 |
Description
Input
Output
Sample Input
1 10 1 -1 2 2 3 -3 4 -4 5 -5
Sample Output
13
Hint
Source
#include<iostream> #include<cstdio> #include<cstring> #include<string> #include<cmath> #include<cstdlib> #include<algorithm> using namespace std; #define max(a,b) a>b?a:b #define MAXV 50010 #define inf -10010 int lt[MAXV],rt[MAXV],a[MAXV],rtm[MAXV]; int main() { int t,n,i,temp; scanf("%d",&t); while(t--){ scanf("%d",&n); for(i=1;i<=n;i++) scanf("%d",&a[i]); temp=inf;lt[1]=a[1];rt[n]=a[n]; for(i=2;i<=n;i++){ lt[i]=max(a[i],lt[i-1]+a[i]); } for(i=n-1;i>=1;i--){ rt[i]=max(a[i],rt[i+1]+a[i]); } rtm[n]=rt[n]; for(i=n-1;i>=1;i--) rtm[i]=max(rtm[i+1],rt[i]); int ma=inf; for(i=2;i<=n;i++){ ma=max(ma,lt[i-1]+rtm[i]); } printf("%d\n",ma); } return 0; }
标签:des blog http io ar os sp for strong
原文地址:http://www.cnblogs.com/a972290869/p/4099522.html