C++ || Cumulative property
\nclass Solution {\npublic:\n    /*\n        [1   8]\n        \n        list of segment pairs which make target values[{1 3} {2 2} {6, 7} {6, 8}]\n        \n   
```\nclass Solution {\npublic:\n    /*\n        [1   8]\n        \n        list of segment pairs which make target values[{1 3} {2 2} {6, 7} {6, 8}]\n        \n        [0] = inf                          = 1\n        [1] = 3 {1, 3} = 1                 = 1\n        [2] = 1 {2, 2}                     = 1\n        [3] = inf                          = 2\n        [4] = inf                          = 2\n        [5] = inf                          = 2\n        [6] = min(3 {6, 8} , 2 {6, 7}) = 2 = 2\n        [7] = inf                          = inf\n        [8] = inf                          = inf\n        \n    */\n    #define inf 0x3f3f3f3f\n    \n    int non_overlapping_min_sub_array_len_from_index[100001];\n    int minSumOfLengths(vector<int>& arr, int target) {\n        memset(non_overlapping_min_sub_array_len_from_index, inf, sizeof non_overlapping_min_sub_array_len_from_index);\n        vector <pair<int, int>> targetMakingPairs;\n        int lf = 0, sum = 0;\n        for (int rt = 0; rt < arr.size(); rt++) {\n            sum += arr[rt];\n            while(sum > target) {\n                sum -= arr[lf++];\n            }\n            if (sum == target) {\n                targetMakingPairs.push_back({lf, rt});\n                non_overlapping_min_sub_array_len_from_index[lf] = min(non_overlapping_min_sub_array_len_from_index[lf], rt - lf + 1);\n            }\n        }\n        \n        if (targetMakingPairs.size() < 2) return -1;\n        \n        for (int index = arr.size() - 1; index >= 0; index--) {\n            non_overlapping_min_sub_array_len_from_index[index] = min(non_overlapping_min_sub_array_len_from_index[index], non_overlapping_min_sub_array_len_from_index[index + 1]);\n        }\n\n        \n        int result = inf;\n        for (int pair_id = 0; pair_id < targetMakingPairs.size(); pair_id++) {\n            result = min(result, targetMakingPairs[pair_id].second - targetMakingPairs[pair_id].first + 1 + non_overlapping_min_sub_array_len_from_index[ targetMakingPairs[pair_id].second + 1 ]);\n        }\n        \n        return result == inf ? -1 : result;\n    }\n};\n```
[]