DP solution || 100 faster || c++
\nclass Solution {\npublic:\n    int maxSum(vector<int>& nums1, vector<int>& nums2) {\n        int n=nums1.size(),m=nums2.size();\n        vector<long long> dp1
```\nclass Solution {\npublic:\n    int maxSum(vector<int>& nums1, vector<int>& nums2) {\n        int n=nums1.size(),m=nums2.size();\n        vector<long long> dp1(n+5,0),dp2(m+5,0);\n        int i=0,j=0;\n        while(i<n and j<m)\n        {\n            if(nums1[i]<nums2[j])\n            {\n                dp1[i+1]=nums1[i]+dp1[i];\n                i++;\n            }\n            else if(nums1[i]>nums2[j])\n            {\n                dp2[j+1]=dp2[j]+nums2[j];\n                j++;\n            }\n            else {\n                dp1[i+1]=dp2[j+1]=max(dp1[i],dp2[j])+nums1[i];\n                i++;\n                j++;\n            }\n        }\n        while(i<n)\n        {\n            dp1[i+1]=dp1[i]+nums1[i];\n            i++;\n        }\n        \n        while(j<m)\n        {\n            dp2[j+1]=dp2[j]+nums2[j];\n            j++;\n        }\n        \n        return max(dp1[n],dp2[m])%1000000007;\n    }\n};\n```
[]