"Dynamic Planning" "RQ208" Olympic torch to Xiamen _ test

Source: Internet
Author: User
Topic description

Background: May 12, under the warm welcome of the people of Xiamen, the Olympic torch symbolizing peace, friendship and holiness finally came to Xiamen and began to pass ...

Description: The mayor of Xiamen announced: "The torch relay to do very meaningful." What do you mean, "meaningful"? The mayor of Xiamen ingenuity gave it a definition: each torchbearer has a meaning value, they can be regarded as a first and last ring, and the value of the torch relay is the maximum and continuous substring of this ring.
For example: The string is-2 2 0 1-48 1, apparently its largest and contiguous substring is 2 0 1, and its and is 3.
Now given the value of the N torch, please figure out the value of the entire torch relay (meaning may be negative) input format

Line 1th an integer n (1<=n<=1000000) represents n a torch hand
Line 2nd has n integers, and each integer is within the range of Longint.
New note: Due to unknown reasons, the normal program is tle at 8 9 103 test points, so the following 3 test points are temporarily closed. Change data range to 5000 output format

The value of the torch relay. Sample input

2 1 3 Sample output

4

Three-dimensional state image

The eldest son of string and, the ring for the chain

#include <iostream> #define MAXN 5000 using namespace std; long a[2* (maxn+1)],ans; int main () {long n; cin>> N for (long i=1;i<=n;++i) {cin>>a[i]; if (a[i]<0) ++ans} if (ans==n) {ans=int_min; for (long I=1;i<=n;++i) if (A[i]>ans) ans=a[i]; else{ans=0 for (long I=1;i<=n;++i) a[i+n]=a[i], for (long Start=1;start<=n;++start) {long temp=0; Art;i-start+1<=n;++i) {if (temp+a[i]<0) temp=0; else temp+=a[i]; if (Temp>ans) ans=temp;}} } cout<<ans<<endl; return 0; }

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.