CCCPaste

Untitled

#include 
//#include 
#include 
#include 
#include 
#include 
#define MOD 1000000007
#define ll long long
using namespace std;
int n;
int arr1[100005];
int arr2[100005];
int memo[100005][2];

int dp (int at, int where){
    if(at==n){
        return 0;
    }
    if(memo[at][where] != -1) return memo[at][where];
    
    int res=0;
    
    if(where == 0 and at+1=arr1[at]){
            res = max(res,dp(at+1,0)+1);
        }
        
        if(arr2[at+1]>=arr1[at]){
            res = max(res,dp(at+1,1)+1);
        }
    }
    else if(where == 1 and at+1=arr2[at]){
            res = max(res,dp(at+1,1)+1);
        }
        
        if(arr1[at+1]>=arr2[at]){
            res=max(res,dp(at+1,0)+1);
        }
    }
    
    return memo[at][where] = res;
}
int main() {
    cin >> n;
    for(int i =0;i> arr1[i];
    
    }
    for(int i = 0;i> arr2[i];
    }
    
    memset(memo, -1, sizeof memo);
    int res = 0;
    for(int i= 0;i