C++ O(M+N) Time O(1) Space 8 Line Solution
\nclass Solution {\npublic:\n    int maxSum(vector<int>& nums1, vector<int>& nums2) {\n        long sum1 = 0, sum2 = 0, ptr1 = 0, ptr2 = 0, lim = (long)10000000
```\nclass Solution {\npublic:\n    int maxSum(vector<int>& nums1, vector<int>& nums2) {\n        long sum1 = 0, sum2 = 0, ptr1 = 0, ptr2 = 0, lim = (long)1000000007;\n        while(ptr1<nums1.size() && ptr2<nums2.size())\n            if(nums1[ptr1]==nums2[ptr2]) sum2 = sum1 = max(sum1, sum2) + nums1[ptr1++], ptr2++;\n            else if(nums1[ptr1]<nums2[ptr2]) sum1+=nums1[ptr1++];\n            else sum2+=nums2[ptr2++];\n        while(ptr1<nums1.size()) sum1+=nums1[ptr1++];\n        while(ptr2<nums2.size()) sum2+=nums2[ptr2++];\n        return max(sum1,sum2)%lim;\n    }\n};\n```
[]