标签:poj
Time Limit: 3000MS | Memory Limit: 65536K | |
Total Submissions: 16329 | Accepted: 6848 |
Description
Give you N integers a1, a2 ... aN (|ai| <=1000, 1 <= i <= N).
Input
Output
Sample Input
5-5 9 -5 11 200
Sample Output
40
#include <iostream> #include <vector> #include <algorithm> using namespace std; int left_v[100005]; int right_v[100005]; int value[100005]; int main() { int Test; while(cin>>Test) { if(!Test) break; left_v[0]=0; right_v[0]=0; left_v[Test+1]=0; right_v[Test+1]=0; int i,max_v=-100000000; for(i=1;i<=Test;i++) { cin>>value[i]; } left_v[1]=value[1]; right_v[Test]=value[Test]; for(i=2;i<=Test;i++) { left_v[i]=max(left_v[i-1]+value[i],value[i]); } for(i=Test-1;i>=1;i--) { right_v[i]=max(right_v[i+1]+value[i],value[i]); } for(i=2;i<=Test;i++) { left_v[i]=max(left_v[i-1],left_v[i]); } for(i=Test-1;i>=1;i--) { right_v[i]=max(right_v[i+1],right_v[i]); } for(i=1;i<Test;i++) { if(left_v[i]+right_v[i+1]>max_v) max_v=left_v[i]+right_v[i+1]; } cout<<max_v<<endl; } return 0; }
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:poj
原文地址:http://blog.csdn.net/u010885899/article/details/46763237