Simple DP Approach
dp[i][0] - stores the length of longest non-decreasing subarray which starts at ith index and the element chosen at ith index is a[i]\n\ndp[i][1] - stores the l
dp[i][0] - stores the length of longest non-decreasing subarray which starts at ith index and the element chosen at ith index is a[i]\n\ndp[i][1] - stores the length of longes non-decreasing subarray which starts at ith index and the element chosen at ith index is b[i]\n\n```\nclass Solution {\npublic:\n    int maxNonDecreasingLength(vector<int>& a, vector<int>& b) {\n        int n=a.size(),ans=1;\n        vector<vector<int>> dp(n,vector<int>(2,-1));\n        dp[n-1][0]=1;\n        dp[n-1][1]=1;\n        \n        for(int i=n-2;i>=0;--i) {\n            dp[i][0]=1;\n            if(a[i+1]>=a[i])\n                dp[i][0]=1+dp[i+1][0];\n            if(b[i+1]>=a[i])\n                dp[i][0]=max(dp[i][0],1+dp[i+1][1]);\n            \n            dp[i][1]=1;\n            if(a[i+1]>=b[i])\n                dp[i][1]=1+dp[i+1][0];\n            if(b[i+1]>=b[i])\n                dp[i][1]=max(dp[i][1],1+dp[i+1][1]);\n            \n            ans=max({ans,dp[i][0],dp[i][1]});\n        }\n        \n        return ans;\n    }\n};\n```
['Dynamic Programming', 'C', 'C++']