------
## 最终结论
```python
def maxDotProduct(nums1, nums2):
    n, m = len(nums1), len(nums2)
    dp = [[float('-inf')] * (m + 1) for _ in range(n + 1)]

    # Fill the dp table
    for i in range(1, n + 1):
        for j in range(1, m + 1):
            dp[i][j] = max(dp[i - 1][j - 1] + nums1[i - 1] * nums2[j - 1], 
                           dp[i - 1][j], 
                           dp[i][j - 1],
                           nums1[i - 1] * nums2[j - 1]) # also consider single element case

    return max(max(row) for row in dp)

# Example usage
print(maxDotProduct([2, 1, -2, 5], [3, 0, -6])) # Output: 18
print(maxDotProduct([3, -2], [2, -6, 7])) # Output: 21
print(maxDotProduct([-1, -1], [1, 1])) # Output: -1
```