Max Sequence
Time Limit: 3000MS |
|
Memory Limit: 65536K |
Total Submissions: 16001 |
|
Accepted: 6715 |
Description
Give you N integers a1, A2 ... an (|ai| <=1000, 1 <= i <= N).
You should output S.
Input
The input would consist of several test cases. For each test case, one of the integer n (2 <= n <= 100000) is given on the first line. Second line contains N integers. The input is terminated by a, with N = 0.
Output
For each test of the input, print a line containing S.
Sample Input
5-5 9-5 11 200
Sample Output
40
Approximate test instructions: Give a series, find out the number of disjoint in the sequence of two sub-segments and, require sub-segment and maximum.
1#include <stdio.h>2 intMain ()3 {4 intleft[100005];5 intright[100005];6 inta[100005];7 while(1)8 {9 intn,i;Tenscanf"%d",&n); One if(n==0) A Break; - for(i=0; i<n;i++) -scanf"%d",&a[i]); the intSuml=0; - intmax=-99999999; - for(i=0; i<n;i++)//Maximum number of consecutive substrings from left to right to end of I//If this cycle does not understand, you can do the next hdu1003 - { +suml=suml+A[i]; - if(suml>max) +max=SumL; A if(suml<0) atSuml=0; -left[i]=Max; - } -max=-99999999; - inttmp=-99999999; - intSumr=0; in for(i=n-1; i>=1; i--) - { tosumr=sumr+A[i]; + if(sumr>max) -max=Sumr; the if(sumr<0) *Sumr=0; $ if(tmp<max+left[i-1])Panax Notoginsengtmp=max+left[i-1]; - } theprintf"%d\n", TMP); + } A return 0; the}
POJ-2593 Max Sequence