Python3 Iterative DP. Commented
Iterative DP solution\n\nFirst merge subarray 0 through i and find best next segment.\nnow for end position of next segment merging to i is better than merging 
Iterative DP solution\n\nFirst merge subarray 0 through i and find best next segment.\nnow for end position of next segment merging to i is better than merging all the way to 0.\n\n# Code\n```\nclass Solution:\n    def findMaximumLength(self, nums: List[int]) -> int:\n        n=len(nums)\n        nums+=[float(\'inf\')]\n        presum=[0]+list(accumulate(nums))\n\n        best_left_index=defaultdict(int)# assume best subarray to merge left is [0,i)\n        dp=defaultdict(int) # dp[i]= count no of subarrays to left of i.\n        \n        for i in range(1,n+1):\n            #choose smallest current subarray.(maximize left index.)\n            best_left_index[i]=max(best_left_index[i-1],best_left_index[i]) \n\n            # If we are merging [left_index,i) , let next segment is [i,right_index).\n            # choose smallest possible right_index. such that range_sum( [left_index,i) ) <= range_sum( [i,right_index) ).\n            # presum[i]-presum[left_index]<=presum[right_index]-presum[i].\n            # 2*presum[i]-presum[left_index]<=presum[right_index]\n            # binary search for smallest possible right index.\n            right_index=bisect.bisect_left(presum,2*presum[i]-presum[best_left_index[i]])   \n\n            best_left_index[right_index]=i\n\n        return dp[n]\n\n```
['Python3']