Title Description
Given a sequence, wherein the selected period of continuous and non-empty and that this maximum.
Input Format
The first line is a positive integer NN N, denotes the length of the sequence.
The second line contains NN N absolute value is not greater than 1.00001 billion . 1 0 0 0 integer of 0 AiA_i A I , this sequence is described column.
Output Format
An integer, the largest sub-segment and how much. The minimum length of the sub segment is . 11 1
Sample input and output
Input # 1
7 2 -4 3 -1 2 -4 3
Output # 1
4
Description / Tips
[Sample Description]
2, -4,3, -1,2, -4,32, -4,3, -1,2, -4,3 2 , - . 4 , 3 , - . 1 , 2 , - . 4 , 3, the maximum the sub-segments and 4, the sub-segment 3, -1,23, 1,2 3 , - . 1 , 2.
[Agreed] with the scale data
For 40% 40 \% . 4 0 % of the data, there N≤2000N 2000 ≤ N ≤ 2 0 0 0.
For 100% 100 \% . 1 0 0 % of the data, there N≤200000N 200000 ≤ N ≤ 2 0 0 0 0 0.
It is still difficult for the popularity - and thought acridine prefix -
1 #include<bits/stdc++.h> 2 using namespace std; 3 int n,k,ans,minn,maxn=-9999; 4 int a[200010],b[200010]; 5 int main() 6 { 7 cin>>n; 8 for(int i=1;i<=n;i++) 9 { 10 cin>>a[i]; 11 a[i]+=a[i-1];//前缀和 12 } 13 B [ . 1 ] = A [ . 1 ]; Minn = min ( 0 , A [ . 1 ]); // A [. 1] may be negative 14 for ( int I = 2 ; I <= n-; I ++ ) 15 { 16 B [I] = a [I] -minn; // Minn subtracting the minimum required prefix . 17 Minn = min (Minn, a [I]); // remember to update 18 is } . 19 for ( int I = . 1 ; I < n-=; i ++ ) 20 is MAXN = max (MAXN, B [i]); // B [i] for the ending of the maximum i and sub-segment 21 is COUT << MAXN; 22 return 0; 23 }