Python | dp + monotonic stack + binary search | O(nlogn)
Code\n\nfrom bisect import bisect_right\nclass Solution:\n    def findMaximumLength(self, nums: List[int]) -> int:\n        n = len(nums)\n        stack = [(0,0
# Code\n```\nfrom bisect import bisect_right\nclass Solution:\n    def findMaximumLength(self, nums: List[int]) -> int:\n        n = len(nums)\n        stack = [(0,0,0)]\n        prefix = 0\n        for j in range(n):\n            prefix += nums[j]\n            i = bisect_right(stack, (prefix, float(\'inf\'), float(\'inf\')))\n            prefixlast, prefi, di = stack[i-1]\n            curprefixlast = prefix+prefix-prefi\n            while stack and stack[-1][0] >= curprefixlast:\n                stack.pop() \n            stack.append((prefix+prefix-prefi, prefix, di+1))\n            \n        return stack[-1][2]\n\n\n\n```
['Python3']