C++/Python, dynamic programming solution with explanation
dp[i][0] is max size of Longest Non-decreasing Subarray when we select nums1[i].\ndp[i][1] is max size of Longest Non-decreasing Subarray when we select nums2[i
dp[i][0] is max size of Longest Non-decreasing Subarray when we select nums1[i].\ndp[i][1] is max size of Longest Non-decreasing Subarray when we select nums2[i].\n\nAt first,\ndp[0][0] = dp[0][1] = 1, there is only one element in the nums3.\n\nAnd to determine nums3[i],\nand should check if nums1[i] >= nums1[i-1] and nums1[i] >= nums2[i-1],\nalso nums2[i] >= nums1[i-1] and nums2[i] >= nums2[i-1].\n\ndp[i][0] = 1 + max(dp[i-1][0] if nums1[i] >= nums1[i-1] else 0, dp[i-1][1] if nums1[i] >= nums2[i-1] else 0)\ndp[i][1] = 1 + max(dp[i-1][0] if nums2[i] >= nums1[i-1] else 0, dp[i-1][1] if nums2[i] >= nums2[i-1] else 0)\n\ntc is O(n), sc is O(1)\n### python\n```python\nclass Solution:\n    def maxNonDecreasingLength(self, nums1: List[int], nums2: List[int]) -> int:\n        ans = 0\n        dp_0 = dp_1 = 0\n        for i, (x, y) in enumerate(zip(nums1, nums2)):\n            cur_0 = 1 + max(dp_0 if i and x >= nums1[i-1] else 0, dp_1 if i and x >= nums2[i-1] else 0)\n            cur_1 = 1 + max(dp_0 if i and y >= nums1[i-1] else 0, dp_1 if i and y >= nums2[i-1] else 0)\n            dp_0, dp_1 = cur_0, cur_1\n            ans = max(ans, dp_0, dp_1)\n        return ans\n```\n### c++\n```cpp\nclass Solution {\npublic:\n    int maxNonDecreasingLength(vector<int>& nums1, vector<int>& nums2) {\n        int dp_0 = 1, dp_1 = 1, ans = 1;\n        for (int i = 1, cur_0, cur_1; i < nums1.size(); i+=1) {\n            cur_0 = 1 + max(nums1[i] >= nums1[i-1]? dp_0:0, nums1[i] >= nums2[i-1]?dp_1:0);\n            cur_1 = 1 + max(nums2[i] >= nums1[i-1]? dp_0:0, nums2[i] >= nums2[i-1]?dp_1:0);\n            dp_0 = cur_0, dp_1 = cur_1;\n            ans = max(ans, max(dp_0, dp_1));\n        }\n        return ans;\n    }\n};\n```
['Dynamic Programming', 'C', 'Python']