<p>Given two integer arrays&nbsp;<code>arr1</code> and <code>arr2</code>, return the minimum number of operations (possibly zero) needed&nbsp;to make <code>arr1</code> strictly increasing.</p>

<p>In one operation, you can choose two indices&nbsp;<code>0 &lt;=&nbsp;i &lt; arr1.length</code>&nbsp;and&nbsp;<code>0 &lt;= j &lt; arr2.length</code>&nbsp;and do the assignment&nbsp;<code>arr1[i] = arr2[j]</code>.</p>

<p>If there is no way to make&nbsp;<code>arr1</code>&nbsp;strictly increasing,&nbsp;return&nbsp;<code>-1</code>.</p>

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

<pre>
<strong>Input:</strong> arr1 = [1,5,3,6,7], arr2 = [1,3,2,4]
<strong>Output:</strong> 1
<strong>Explanation:</strong> Replace <code>5</code> with <code>2</code>, then <code>arr1 = [1, 2, 3, 6, 7]</code>.
</pre>

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

<pre>
<strong>Input:</strong> arr1 = [1,5,3,6,7], arr2 = [4,3,1]
<strong>Output:</strong> 2
<strong>Explanation:</strong> Replace <code>5</code> with <code>3</code> and then replace <code>3</code> with <code>4</code>. <code>arr1 = [1, 3, 4, 6, 7]</code>.
</pre>

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

<pre>
<strong>Input:</strong> arr1 = [1,5,3,6,7], arr2 = [1,6,3,3]
<strong>Output:</strong> -1
<strong>Explanation:</strong> You can&#39;t make <code>arr1</code> strictly increasing.</pre>

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

<ul>
	<li><code>1 &lt;= arr1.length, arr2.length &lt;= 2000</code></li>
	<li><code>0 &lt;= arr1[i], arr2[i] &lt;= 10^9</code></li>
</ul>

<p>&nbsp;</p>

class Solution {
public:
    int solve(int index,int prev,vector<int>& arr1, vector<int>& arr2,vector<unordered_map<int,int>> &dp){
        if(index==arr1.size()) return 0;
        int opt1=INT_MAX,opt2=INT_MAX;

        if(dp[index].count(prev)) return dp[index][prev];
        if(arr1[index]>prev ){
            opt1=solve(index+1,arr1[index],arr1,arr2,dp);
            auto a=upper_bound(arr2.begin(), arr2.end(), prev);
            if(a!=arr2.end() && *a<arr1[index]){
                opt2=1+solve(index+1,*a,arr1,arr2,dp);
            }
        }
        else{
            auto a=upper_bound(arr2.begin(), arr2.end(), prev);
            if(a==arr2.end() || *a<=prev) return 1e9;            
            opt2=1+solve(index+1,*a,arr1,arr2,dp);
        }
        
        return dp[index][prev]=min(opt1,opt2);
    }
    int makeArrayIncreasing(vector<int>& arr1, vector<int>& arr2) {
        sort(arr2.begin(),arr2.end());
        vector<unordered_map<int,int>> dp(arr1.size());
        int ans=solve(0,-1,arr1,arr2,dp);
        if (ans>2000) return -1;
        return ans;
    }
};
























        // for(int i=1;i<n;i++){
        //     if(arr1[i-1]>=arr1[i]){

        //         auto a=upper_bound(arr2.begin(), arr2.end(), arr1[i-2]);
        //         if(a==arr2.end() ) return -1;

        //         if(*a>=arr1[i]){
        //             auto b=upper_bound(arr2.begin(), arr2.end(), *a);
        //             if(b==arr2.end()) return -1;
        //             if(*a==arr1[i-1]) ans++;
        //             else ans+=2;

        //             arr1[i-1]=*a;
        //             arr1[i]=*b;
        //         }
        //         else{
        //             arr1[i-1]=*a;
        //             ans++;
        //         }
        //     }
        // }
90165