c++ | 83% faster than all | easy
\n# Code\n\nclass Solution {\npublic:\n    int maxSum(vector<int>& A, vector<int>& B) {\n        int i = 0, j = 0, n = A.size(), m = B.size();\n        long a =
\n# Code\n```\nclass Solution {\npublic:\n    int maxSum(vector<int>& A, vector<int>& B) {\n        int i = 0, j = 0, n = A.size(), m = B.size();\n        long a = 0, b = 0, mod = 1e9 + 7;\n        while (i < n || j < m) {\n            if (i < n && (j == m || A[i] < B[j])) {\n                a += A[i++];\n            } else if (j < m && (i == n || A[i] > B[j])) {\n                b += B[j++];\n            } else {\n                a = b = max(a, b) + A[i];\n                i++, j++;\n            }\n        }\n        return max(a, b) % mod;\n    }\n};\n```
['C++']