Maximum Subarray Sum

  • + 4 comments

    OK, I need help on this one... I am getting the prefix sums in a vector s, and for each element i of the initial vector, I find the smallest element of s greater than s[i]. The difference between the two (mod M) gives me the max value for any subarray endind at i.

    For efficiency, I keep only one copy of each value in s. I tried keeping these values in a set or in a hashmap.

    How can I do more efficient than this? I keep getting time out errors... :(