Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- solve (arr: ARRAY [INTEGER]): ARRAY [INTEGER]
- local
- ans, ans_l, ans_r, sum, min_sum, min_pos, i, cur: INTEGER_32
- any_non_negative: BOOLEAN
- do
- any_non_negative := false
- ans := arr [1]
- ans_l := 1
- ans_r := 1
- sum := 0
- min_sum := 0
- min_pos := 0
- from
- i := 1
- until
- i > arr.count
- loop
- if arr[i] >=0 then
- any_non_negative := true
- end
- sum := sum + arr [i]
- cur := sum - min_sum
- if cur > ans then
- ans := cur
- ans_l := min_pos + 1
- ans_r := i
- end
- if sum < min_sum then
- min_sum := sum
- min_pos := i
- end
- i := i + 1
- end
- if any_non_negative then
- Result := arr.subarray (ans_l, ans_r)
- else
- Result := create {ARRAY[INTEGER_32]}.make_empty
- end
- end
Add Comment
Please, Sign In to add comment