o(n), 2 state dp, one pass
\nclass Solution {\npublic:\n    int maximumSum(vector<int>& nums) {\n        int n = nums.size();\n        int dp[n][2];\n        int ans;\n        ans = dp[0]
```\nclass Solution {\npublic:\n    int maximumSum(vector<int>& nums) {\n        int n = nums.size();\n        int dp[n][2];\n        int ans;\n        ans = dp[0][0] = dp[0][1] = nums[0];\n        for (int i = 1; i < n; ++i) {\n            dp[i][0] = nums[i] + max(dp[i-1][0], 0);\n            dp[i][1] = max(dp[i-1][0], nums[i] + max(0, max(dp[i-1][0], dp[i-1][1])));\n            ans = max({ans, dp[i][0], dp[i][1]});\n        }\n        return ans;\n    }\n};\n```
[]