Maximum Cyclic Segment Sum by uru

var a:array[0..99]of comp;n,i,j,k,s,m,x,y:comp;begin
repeat n:=0;m:=0;repeat
read(a[n]);inc(n)until eoln;for j:=n to 2*n-1do
a[j]:=a[j-n];for i:=0to n-1do for j:=0to n-1do begin
s:=0;for k:=i to i+j do s:=s+a[k];if s>m then begin
x:=i;y:=i+j;m:=s;end;end;for k:=x to y-1do write(a[k],^`);writeln(a[y])until 1=0end.

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

download

return to the top page