------
## 最终结论
```python
def minSumOfLengths(arr, target):
    n = len(arr)
    prefix_sum = {0: -1}
    current_sum = 0
    min_len = float('inf')
    result = float('inf')
    
    dp = [float('inf')] * n
    
    for i in range(n):
        current_sum += arr[i]
        
        if current_sum - target in prefix_sum:
            start_idx = prefix_sum[current_sum - target]
            if start_idx != -1:
                min_len = min(min_len, i - start_idx)
            if start_idx >= 0 and dp[start_idx] != float('inf'):
                result = min(result, dp[start_idx] + i - start_idx)
        
        dp[i] = min_len
        prefix_sum[current_sum] = i
    
    return result if result != float('inf') else -1
```