|
|
back to boardI have TLE... Help... This is finding maxinmum sum in p array... I have TLE on test #13... Help... procedure solve; var i,j:longint; begin a[1]:=p[1]; max:=a[1]; for i:=2 to n do begin a[i]:=p[i]+a[i-1]; if max<a[i] then max:=a[i]; end; for i:=1 to n do for j:=i to n do if max<a[j]-a[i]+p[i] then max:=a[j]-a[i]+p[i]; end; Re: I have TLE... Help... This can be done in O(N), yours is O(N²) |
|
|