The problem of NYOJ-745 ants (ii) "Dynamic Planning"

Source: Internet
Author: User

The problem of Ants (ii) time limit: ms | Memory limit:65535 KB Difficulty:3
Describe

It rained, it rained, the ants moved.

It is known that n kinds of ingredients need to be removed, and these ingredients form a circle from 1 to N in turn. The little ant has a value VI for each of the ingredients, of course, if VI is less than 0, it means the ant hates the ingredients. Because it is going to rain soon, so ants can only move once, but can remove a continuous section of the ingredients. Time is urgent, you can help small ants, let it move away from the ingredients love value and maximum.

Input
There are several sets of test data (end with EOF). There are two rows for each set of data, and the first row has an N, indicating that there are n kinds of ingredients lined up in a circle. (1 <= n<= 50000) The second row has n number, which represents the ant's favorite value VI of the nth kind of ingredients. ( -10^9 <= Vi <= 10^9)
Output
The
maximum value of the sum of the favorite values of the ingredients that the small ant can move out.
Sample input
33-1 25-8 5-1 3-9
Sample output
57
Source
Ant Series
Uploaded by
acm_ Li Rubing
#include <stdio.h>#include<algorithm>using namespacestd;Long  Longdp[50001];Long Longa[50001];Long Longdpp[50001];intMain () {intN;  while(~SCANF ("%d",&N)) {        inti; Long Longmaxn,minn,sum=0;  for(i=0; i<n;++i) {scanf ("%lld",&A[i]); Sum+=A[i]; } dp[0]=a[0];  for(i=1; i<n;++i) {Dp[i]=max (dp[i-1]+A[i],a[i]); } MAXN=dp[0];  for(i=1; i<n;++i) {MAXN=Max (maxn,dp[i]); } dpp[0]=a[0];  for(i=1; i<n;++i) {Dpp[i]=min (dpp[i-1]+A[i],a[i]); } Minn=dpp[0];  for(i=1; i<n;++i) {Minn=min (minn,dpp[i]); } printf ("%lld\n", Max (sum-minn,maxn)); }    return 0;}

The problem of NYOJ-745 ants (ii) "Dynamic Planning"

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.