1014
This problem is very valuable to do, at first glance not difficult, but do not know how to do it.
The idea at first is to count each negative as the beginning, and time out.
Later thought of the topic is actually to find an opening point, so that the beginning point to calculate the sub-array and the smallest,
So, is this starting point the smallest negative number in the array?
Press this code, submit, Answer wrong
To cite a counter-example
6
-7 8-6 2-6 8
-7 is the smallest, but -6+2-6 is smaller than-7
So we should first find the smallest and sub-arrays in the array, but doesn't that turn out to be the original problem? (The answer can be obtained from any one of the array to begin the request.)
At this point, we can consider this problem, if the minimum and the array does not involve the problem of loops, then you can find the general method, and then at the end of the arrays at the beginning of the next to find the most large
If this minimum and array exists in the end-to-end position, then we can find the answer from the beginning to the maximum and (that is, from the middle of the array).
The code is as follows
1#include <cstdio>2#include <cstdlib>3#include <cstring>4#include <iostream>5 using namespacestd;6 intnum0[100002];7 intnum[100002];8 9 intN;Ten One intFindintstart) { A intMaxi =0; - intCNT =0; - for(inti = start; I < n; i++) { the if(CNT <0) { -CNT =Num[i]; - } - Else { +CNT = cnt +Num[i]; - } + if(CNT >Maxi) { AMaxi =CNT; at } - } - for(inti =0; I < start; i++) { - if(CNT <0) { -CNT =Num[i]; - } in Else { -CNT = cnt +Num[i]; to } + if(CNT >Maxi) { -Maxi =CNT; the } * } $ returnMaxi;Panax Notoginseng } - intMainintargcChar Const*argv[]) the { + while(SCANF ("%d", &n)! =EOF) { A intj =0; thememset (NUM,0,sizeof(num)); + intState =0; - for(inti =0; I < n; i++) { $scanf"%d",&num0[i]); $ if(Num0[i] >0) { - if(state = =1) { -J + +; theState =0; - }WuyiNum[j++] =Num0[i]; the - } Wu Else { -NUM[J] = Num[j] +Num0[i]; About if(state = =0) { $State =1; - } - - } A } +n = j +State ; the - /*for (int i = 0; i < n; i++) { $ printf ("%d", Num[i]); the } the puts ("");*/ the intLocal =1002,Global=1002; the intMini =-1; - intSumi =0; in for(inti =0; I < n; i++) { theLocal = min (local+Num[i], num[i]); the if(Local <Global) { AboutMini =i; the Global=Local; the } the } + intMaxa = Find (0); - intMaxt =find (mini); the if(Maxa <maxt) {BayiMaxa =Maxt; the } theprintf"%d\n", Maxa); - } - return 0; the}