POJ-2593 Max Sequence

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.