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"