<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>

// **ank**//
#include <bits/stdc++.h>
using namespace std;
#define ll                     long long int
#define all(v)                 v.begin(), v.end()
#define maxi(v)                *max_element(v.begin(), v.end())
#define vecsum(v)              accumulate(v.begin(), v.end(), 0)
#define mini(v)                *min_element(v.begin(), v.end())
#define sortd(v)                sort(v.begin(), v.end(), greater<int>())
#define read(a, n)             for(int i=0;i<n;i++)    cin >> a[i]
#define print(a, n)            for(int i=0;i<n;i++)    cout << a[i] << " "; cout << endl
#define rep(a,n,b,i)           for(int i=a;i<n;i+=b)       
#define M                       1000000007
#define pb                      push_back
#define sz                      size()
#define len                     length()
#define fir                     first
#define sec                     second
#define cy                      cout << "YES" << endl
#define cn                      cout << "NO" << endl 
#define mll                     map<ll,ll>
#define mcl                     map<char,ll>
#define msl                     map<string,ll>
#define si                      set<ll>
#define sc                      set<char>
using pp = pair<ll,ll>;
using vl = vector<ll>;
using vc = vector<char>;
using vi = vector<int>;
using vvl=vector<vector<ll>>;
using vvc=vector<vector<char>>;

 class Solution{
public:
    int maximumSum(vector<int>& arr) {
        ll n=arr.sz;
        vl max_end(n),max_start(n);
        max_end[0]=arr[0];
        max_start[n-1]=arr[n-1];
        ll ans=arr[0];
        for(int i=1;i<n;i++){
            max_end[i]=max((ll)arr[i],max_end[i-1]+arr[i]);
            ans=max(ans,max_end[i]);
        }
        for(int i=n-2;i>=0;i--){
            max_start[i]=max((ll)arr[i],max_start[i+1]+arr[i]);
            ans=max(ans,max_start[i]);
        }
       
        for(int i=1;i<n-1;i++){
            ans=max({ans,max_end[i-1]+max_start[i+1]});
        }
        return ans;
    }
};
28900