C++ || MEMOIZATION || DP || BINARY SEARCH || PREFIX SUM
\n#define ll long long int\n    int t[100005][3] ;\n    ll compute(vector<ll>&presum , ll target , int id  , ll k , int n){\n        if(k == 0){\n            re
```\n#define ll long long int\n    int t[100005][3] ;\n    ll compute(vector<ll>&presum , ll target , int id  , ll k , int n){\n        if(k == 0){\n            return 0 ;\n        }\n        if(id >= n){\n            return INT_MAX ;\n        }\n        if(t[id][k] != -1){\n            return t[id][k] ;\n        }\n        ll ans = compute(presum , target , id+1 , k , n) ;\n        auto lb = lower_bound(presum.begin() , presum.end() , presum[id-1] + target) ;\n        if(lb != presum.end() && *lb == presum[id-1] + target){\n            int pos = lb - presum.begin() ;\n            ans = min(ans , pos-id+1 + compute(presum , target , pos+1 , k-1 , n)) ;\n        }\n        return t[id][k] = ans ;\n    }\n    int minSumOfLengths(vector<int>& arr, int target) {\n        int n= arr.size() ;\n        \n        memset(t , -1 , sizeof(t)) ;\n        vector<ll>presum(n+1,0) ;\n        for(int i = 1 ; i<=n; i++){\n            presum[i] = presum[i-1] + arr[i-1] ;\n        }\n        ll ans = compute(presum , target , 1 , 2 , n+1) ;\n        if(ans >= INT_MAX){\n            return -1 ;\n        }\n        return ans ;\n    }\n```
['Dynamic Programming', 'Memoization', 'C', 'Binary Tree', 'Prefix Sum']