<p>Given an array of integers, return the maximum sum for a <strong>non-empty</strong>&nbsp;subarray (contiguous elements) with at most one element deletion.&nbsp;In other words, you want to choose a subarray and optionally delete one element from it so that there is still at least one element left and the&nbsp;sum of the remaining elements is maximum possible.</p>

<p>Note that the subarray needs to be <strong>non-empty</strong> after deleting one element.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> arr = [1,-2,0,3]
<strong>Output:</strong> 4
<strong>Explanation: </strong>Because we can choose [1, -2, 0, 3] and drop -2, thus the subarray [1, 0, 3] becomes the maximum value.</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> arr = [1,-2,-2,3]
<strong>Output:</strong> 3
<strong>Explanation: </strong>We just choose [3] and it&#39;s the maximum sum.
</pre>

<p><strong class="example">Example 3:</strong></p>

<pre>
<strong>Input:</strong> arr = [-1,-1,-1,-1]
<strong>Output:</strong> -1
<strong>Explanation:</strong>&nbsp;The final subarray needs to be non-empty. You can&#39;t choose [-1] and delete -1 from it, then get an empty subarray to make the sum equals to 0.
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= arr.length &lt;= 10<sup>5</sup></code></li>
	<li><code>-10<sup>4</sup> &lt;= arr[i] &lt;= 10<sup>4</sup></code></li>
</ul>

class Status:
    NOUSE = 0
    DELETED = 1

class Solution:
    def maximumSum(self, arr: List[int]) -> int:
        memo = {}
        res = self.dfs(arr, 0, Status.NOUSE, memo)
        return max(memo.values())

    def dfs(self, arr, index, deleted, memo):
        if index == len(arr):
            return float('-inf')
        if (index, deleted) in memo:
            return memo[(index, deleted)]

        res = max(self.dfs(arr, index + 1, deleted, memo) + arr[index], arr[index])
        if deleted == Status.NOUSE:
            res = max(res, self.dfs(arr, index + 1, Status.DELETED, memo))
        
        memo[(index, deleted)] = res

        return memo[(index, deleted)]


        

    def maximumSumIter(self, arr: List[int]) -> int:
        dp = [
            [float('-inf'), float('-inf')], 
            [float('-inf'), float('-inf')],
        ]
        res = float('-inf')
        for i in range(1, len(arr) + 1):
            dp[i % 2][Status.NOUSE] = max(
                arr[i - 1], 
                dp[(i - 1) % 2][Status.NOUSE] + arr[i - 1]
            )
            dp[i % 2][Status.DELETED] = max(
                dp[(i - 1) % 2][Status.NOUSE],
                dp[(i - 1) % 2][Status.DELETED] + arr[i - 1],
                arr[i - 1],
            )
            res = max(max(dp[i % 2]), res)
        return res


        dp = [[float('-inf'), float('-inf')] for _ in range(len(arr) + 1)]
        res = float('-inf')
        for i in range(1, len(arr) + 1):
            dp[i][Status.NOUSE] = max(
                arr[i - 1], 
                dp[i - 1][Status.NOUSE] + arr[i - 1]
            )
            dp[i][Status.DELETED] = max(
                dp[i - 1][Status.NOUSE],
                dp[i - 1][Status.DELETED] + arr[i - 1],
                arr[i - 1],
            )
            res = max(max(dp[i]), res)
        return res
66300