Get maximum score - Leetcode

This is the link to the question :

here is my solution :

the code is passing all the test cases apart from only the last test case for which it is giving wrong answer.
can you please point out the mistake in my code?

my approach :

-> first of all i have stored all the elements that are common in both the arrays in a vector V.

-> then i have stored the sum between every two such elements in array a in the map a1 and that of array 2 in the map b1.

-> after that i have traversed the V vector and added to my final answer the maximum sum between the current number and the next number which are a part of V. that sum was already stored in a1 for array a and in b1 for array b.

Its a complex issue since your logic may look fool-proof whereas actually it is not. The problem lies in the implementation of step 2 and 3 since you are missing on test cases.
This is the correct solution of the code

int maxSum(vector<int>& arr1, vector<int>& arr2) {
        long long i = 0, j = 0, n = arr1.size() , m= arr2.size() , mod = 1e9+7;
        long long res = 0, sum1 = 0, sum2 = 0;
        
        // when arr1 value is less than the value of arr2 add into sum1 and vise versa
        // when both arr1 and arr2 value is same add maximum of them into result and also add same value into result and reset sum1 and sum2
        // by doing this we are ensuring that added value in result is always maximum till common value found
        
        while(i < n && j < m){
            if(arr1[i] < arr2[j]) sum1 += arr1[i++];
            else if(arr1[i] > arr2[j]) sum2 += arr2[j++];
            else{
                res += max(sum1,sum2);
                sum1 = 0,sum2 = 0;
                while(i < n && j < m && arr1[i] == arr2[j])
                {
                    res += arr1[i];
                    i++;
                    j++;
                }
            }
        }
        while(i < n) sum1 += arr1[i++];  // remaining element of any array
        while(j < m) sum2 += arr2[j++];
        res += max(sum1,sum2);
        return (res + mod) % mod;
    }

i am not able to understand the problem in my logic

You are missing testcases in your step 2-3