-1 0 010 1 48 0 3
The first code is as follows
1#include <cstdio>2#include <cstdlib>3#include <iostream>4#include <algorithm>5 6 using namespacestd;7 intn;8 intnum[100002];9 Ten intMainintargcChar Const*Argv[]) one { a //freopen ("input.txt", "r", stdin); - while(SCANF ("%d", &n)! = EOF && n! =0) { - for(inti =0; I < n; i++) { thescanf"%d",&num[i]); - } - intMaxx =-1002, cnt =0; - ints =0, state =0; + intSt =0, et =0; - for(inti =0; I < n; i++) { + if(state = =0) { as =i; atState =1; - } -CNT = cnt +num[i]; - if(cnt >maxx) { -Maxx =cnt; -St =s; inET =i; - } to if(cnt <0) { +CNT =0; -State =0; the } * } $printf"%d%d%d\n", maxx,st,et);Panax Notoginseng } - return 0; the}
Intermediate judgment is a bit complicated, refer to others, modify the following
1#include <cstdio>2#include <cstdlib>3#include <iostream>4#include <algorithm>5 6 using namespacestd;7 intn;8 intnum[100002];9 Ten intMainintargcChar Const*Argv[]) one { a //freopen ("input.txt", "r", stdin); - while(SCANF ("%d", &n)! = EOF && n! =0) { - intMaxx =-1002, cnt =0; the ints =0; - intSt =0, et =0; - - for(inti =0; I < n; i++) { +scanf"%d",&num[i]); - + if(cnt >=0) { aCNT = cnt +num[i]; at } - Else { -CNT =num[i]; -s =i; - } - if(cnt >maxx) { inMaxx =cnt; -St =s; toET =i; + } - } the *printf"%d%d%d\n", maxx,st,et); $ } Panax Notoginseng return 0; -}