51Node 1065----A sequence of minimum positive and n integers a[1],a[2],a[3],..., a[n], from which a subsequence (a[i],a[i+1],... a[j]) is selected to make the and >0 of this subsequence, and this and is all and > The smallest of the 0 sub-sequences. For example: 4,-1,5,-2,-1,2,6,-2. -1,5,-2,-1, the sequence and the 1, are the smallest. Input
Line 1th: Length of the integer sequence N (2 <= N <= 50000) line 2-n+1: n integers
Output
Outputs the smallest positive sub-segment and.
Input example
84-15-2-126-2
Output example
1
The code is as follows:
#include <iostream>#include<algorithm>#include<cstdio>#include<cstring>using namespaceStd;typedefLong LongLL;structnode{LL m; intPOS;} a[50005];BOOLcmpConstNode X,Constnode Y) { returnx.m<y.m;}intMain () {intN; while(SCANF ("%d", &n)! =EOF) {a[0].m=0; a[0].pos=0; for(intI=1; i<=n; i++) {LL x; scanf ("%lld",&x); A[I].M=a[i-1].m+x; A[i].pos=i; } sort (A,a+n+1, CMP); LL T=999999999999; for(intI=1; i<=n; i++) { for(intj=i-1; j>=0; j--) {LL tmp=a[i].m-a[i-1].m; if(a[i].pos<a[i-1].pos) TMP=0-tmp; if(tmp>0) {T=min (t,tmp); Break; } }} cout<<t<<Endl; } return 0;}
51Node 1065----Minimum positive child segments and