Maximum Value Contiguous Subsequence
Your algorithm does not yield the solution. An extension of your algorithm that follows will provide a solution.
You need to mark the extremes of consecutive 1's in the flag array (an obvious observation ). For example, the flag array is 1111101111 then you need to mark 0,5,9 indices (zero based) and for every pair of extremes you need to find the difference computed in prefix sum array. The number of marker indices are of the order of n. So number of pairs are of the order n^2.