<p>Given two arrays of integers with equal lengths, return the maximum value of:</p>

<p><code>|arr1[i] - arr1[j]| + |arr2[i] - arr2[j]| + |i - j|</code></p>

<p>where the maximum is taken over all <code>0 &lt;= i, j &lt; arr1.length</code>.</p>

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

<pre>
<strong>Input:</strong> arr1 = [1,2,3,4], arr2 = [-1,4,5,6]
<strong>Output:</strong> 13
</pre>

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

<pre>
<strong>Input:</strong> arr1 = [1,-2,-5,0,10], arr2 = [0,-2,-1,-7,-4]
<strong>Output:</strong> 20
</pre>

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

<ul>
	<li><code>2 &lt;= arr1.length == arr2.length &lt;= 40000</code></li>
	<li><code>-10^6 &lt;= arr1[i], arr2[i] &lt;= 10^6</code></li>
</ul>

class Solution {
public:
    const int N = 4e4 + 1;
    typedef pair<int, int> ii;
    typedef pair<int, ii > iii;
    int maxAbsValExpr(vector<int>& arr1, vector<int>& arr2) {
        int n = arr1.size();
        vector<iii> p;
        for(int i = 0; i < n; i++)
            p.push_back({arr1[i], {i, arr2[i]}});
        sort(p.begin(), p.end());
        int l1, l2, l3, l4;
        l1 = l2 = l3 = l4 = -1e9;
        int ans = 0;
        for(int i = 0; i < n; i++) {
            int a, j, b;
            a = p[i].first;
            b = p[i].second.second;
            j = p[i].second.first;
            if(l1 != -1e9) {
                ans = max(ans, a + j + b + l1);
                ans = max(ans, a + j - b + l2);
                ans = max(ans, a - j + b + l3);
                ans = max(ans, a - j - b + l4);
            }
             l1 = max(- a - j - b, l1);
             l2 = max(- a - j + b, l2);
             l3 = max(- a + j - b, l3);
             l4 = max(- a + j + b, l4);
        }
        return ans;
    }
};
31400