Maximum Cyclic Segment Sum by tttaki

f[]=[]
f(x:s)=[[x]]++map(x:)(f s)
g[]=[]
g(x:s)=f(x:s)++g s
h[a]=a
h(a:b)|sum a>sum(b!!0)=h(a:tail b)|1>0=h b
i s=filter((<l s).l)$g$map read$s++init s
l=length
m@main=getLine>>=putStrLn.unwords.map show.h.i.words>>m

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

download

return to the top page