Java Prefix sum + dp + binary search
\nclass Solution {\n    public int findMaximumLength(int[] nums) {\n        long[] prefix = new long[nums.length + 1];\n        for (int i = 1; i <= nums.length
```\nclass Solution {\n    public int findMaximumLength(int[] nums) {\n        long[] prefix = new long[nums.length + 1];\n        for (int i = 1; i <= nums.length; i++) {\n            prefix[i] = prefix[i - 1] + nums[i - 1];\n        }\n        // prefix[k] - prefix[i + 1] >= prev => prefix[k] >= prev + prefix[i];\n        int[] dp = new int[nums.length];\n        long[] tail = new long[nums.length];\n        Arrays.fill(tail, Long.MAX_VALUE);\n        dp[0] = 1;\n        tail[0] = nums[0];\n        for (int i = 1; i < nums.length; i++) {\n            if (nums[i] >= tail[i - 1]) {\n                dp[i] = Math.max(dp[i], dp[i - 1] + 1);\n                tail[i] = nums[i];\n            } else {\n                if (dp[i] < dp[i - 1]) {\n                    dp[i] = dp[i - 1];\n                    tail[i] = tail[i - 1] + nums[i];\n                } else if (dp[i] == dp[i - 1]) {\n                    tail[i] = Math.min(tail[i - 1] + nums[i], tail[i]);\n                }\n                int k = find(prefix, tail[i - 1] + prefix[i], i);\n                if (k < prefix.length) {\n                    if (dp[k - 1] < dp[i - 1] + 1) {\n                        dp[k - 1] = dp[i - 1] + 1;\n                        tail[k - 1] = prefix[k] - prefix[i];\n                    } else if (dp[k - 1] == dp[i - 1] + 1) {\n                        tail[k - 1] = Math.min(tail[k - 1], prefix[k] - prefix[i]);\n                    }\n                }\n            }\n        }\n        return dp[nums.length - 1];\n    }\n    \n    int find(long[] prefix, long t, int left) {\n        int l = left;\n        int r = prefix.length;\n        while (l < r) {\n            int mid = l + (r - l) / 2;\n            if (prefix[mid] < t) {\n                l = mid + 1;\n            } else {\n                r = mid;\n            }\n        }\n        return l;\n    }\n}\n```
[]