Maximum Cyclic Segment Sum by 51b

n,I,J,M;a[99];main(i,j,s){for(;~scanf("%d",a+n++);)if(getchar()%4){for(i=n;j=--i;)for(s=0;j<i+n;s>M?I=i,J=j,M=s:0)s+=a[j++%n];for(;I<J;)printf("%d%c",a[I++%n],J+~I?32:10);M=n=0;}}

Note that non-ascii characters in the above source code will be escaped (such as \x9f).

download

return to the top page