C++ Binary Search Simple with STL
Assuming prefix array has the prefix sum of the nums. The main condition to generate is:\n\nleftSum <= midSum <= rightSum  - (i)\n\nleftSum = prefix[i]\nmidSum 
Assuming `prefix` array has the prefix sum of the `nums`. The main condition to generate is:\n```\nleftSum <= midSum <= rightSum  - (i)\n\nleftSum = prefix[i]\nmidSum = prefix[mid] - leftSum\nrightSum = prefix[end] - prefix[mid]\n\n2*prefix[i] <= prefix[mid] <= (prefix[end] + prefix[i])/2  - (ii)\n```\n\nNow we need to find the `lower_bound` for left part and `upper_bound` for right part in `(ii)`. That would give us the interval in which the condition `(i)` would be true. \n\nHere is my code:\n```\nclass Solution {\npublic:\n    int waysToSplit(vector<int>& nums) {\n        vector<int> prefix;\n        int sum = 0;\n        for (int num : nums) {\n            sum += num;\n            prefix.push_back(sum);\n        }\n        \n        int cnt = 0;\n        for (int i = 0; i < nums.size() - 2; ++i) {\n            auto lo = lower_bound(prefix.begin() + i + 1, prefix.end(), \n                                  2*prefix[i]);\n            auto up = upper_bound(prefix.begin() + i + 1, prefix.end() - 1, \n                                  (prefix.back() + prefix[i])/2);\n            if (lo < up)\n                cnt = (cnt + up - lo) % mod;\n        }\n        \n        return cnt;\n    }\n    \nprivate:\n    const int mod = 1e9 + 7;\n};\n```\n\nNote: `prefix.end()-1` for the `upper_bound` is to not search till the end of the `prefix` array since then we won\'t have a 3-way split that way.
[]