57
The problem is the largest field and the deformation, the key point is that the data can be recycled in two steps to solve:
The first step is to find out the maximum field and S1 of this set of data.
The second step, this can be in the first step, to find his minimum field and S2, as well as the sum of all the data s, then, according to the requirements of the topic, the S1 and s-s2 to compare the value of the final result can be obtained.
#include <stdio.h>
#define MAX (x, y) x>y?x:y
#define MIN (x, y) x>y?y:x
Long Long arr[200001];
int main () {Long long n,temp1,max,min,s,temp2,result;
while (~SCANF ("%lld", &n)) {
for (int i=0;i<n;++i) scanf ("%lld", &arr[i]);
for (int i=n,j=0;i<2*n;++i,j++) ARR[I]=ARR[J];
temp1=max=-1000;min=temp2=1000;s=0;
for (int i=0;i<n;++i) {
if (Temp1+arr[i]<arr[i]) temp1=arr[i];
else Temp1+=arr[i];
Max=max (MAX,TEMP1);
if (Temp2+arr[i]>arr[i]) temp2=arr[i];
else Temp2+=arr[i];
Min=min (MIN,TEMP2);
S+=arr[i];
printf ("t=%d temp=%d\n", t,temp);
Result=max (S-min,max);
}
if (result<0) result=0;
printf ("%lld\n", result);}
return 0;
}
Maximum subarray and time limit for the concatenated array: MS | Memory limit:65535 KB Difficulty: 4
-
Describe
-
given an array of n integer elements arr, there are positive and negative numbers in the array, this array is not a normal array, and its end-to-end is connected. One or more contiguous elements in an array can form a sub-array, where such a subarray exists arr[i],... arr[n-1],arr[0],..., arr[j], and now you have this acm_lover One of the most efficient ways to help find out the maximum value of all successive sub-arrays (if the elements in the array are all negative, the maximum is 0, which is not selected).
-
Input
-
The input contains multiple test cases, each with two rows, the first line being an integer n (1=<n<=100000), the length of the array, and the second line entering n integers (the absolute value is not greater than 1000).
-
Output
-
For each test case, output the maximum value of the sub-array and.
-
Sample input
-
61-2 3 5-1 256-1 5 4-7
-
Sample output
-
1014
Two-question code like ...