[Cpp] Simple to understand Using Prefix Sum and Binary Search
\nclass Solution {\n    \npublic:\n    int waysToSplit(vector<int>& nums) {\n        int s = nums.size();\n        vector<int> sum(s, 0);\n        long ans = 0;
```\nclass Solution {\n    \npublic:\n    int waysToSplit(vector<int>& nums) {\n        int s = nums.size();\n        vector<int> sum(s, 0);\n        long ans = 0;\n        sum[0] = nums[0];\n        // get the prefix Sum\n        for(int i = 1; i<s; i++) {\n            sum[i] = sum[i-1] + nums[i];\n        }\n            \n        // Ex: [1,2,2,2,5,0]: A possible cut: [1,2] [2,2], [5,0] --> here the array sum is in sorted order: 3,4,5 so we apply binary search on prefix sum array\n        \n        for(int i = 0; i<s; i++) {\n            \n            //1. the minimum sum of middle array can be sum[i]. So we find the first index j at which the sum is >= sum[i]\n             int a1 = binarySearch1(i+1, s-1, i, sum);\n             if(a1 == -1) continue;\n            \n            //2. the max sum of middle arr can be reminSum/2. So we find the first index k at which the sum <= remainingSum/2\n            int a2 = binarySearch2(i+1, s-1, i, s, sum);\n            if(a2 == -1 || a2 < a1) continue;\n            if(a2 == s-1) a2 -= 1;\n            \n            //3. Now the indices range [a1 a2] are the ways we can break the array. Store it in ans \n          \n            ans += (a2-a1+1);\n        }\n        \n        return ans%(1000000007);\n    }\n    \n    int binarySearch1(int left, int right, int i, vector<int>& sum) {\n\n         int ans1 = -1;\n        while(left<=right) {\n            int mid = left + (right-left)/2;\n            \n            if(sum[mid]-sum[i] >= sum[i]) {\n                // possible ans\n                ans1 = mid;\n                right = mid-1;\n            } else {\n                left = mid+1;\n            }\n        }\n        return ans1;\n    }\n    \n    int binarySearch2(int left, int right, int i, int sz, vector<int>& sum) {\n\n        int ans2 = -1;\n        while(left<=right) {\n            int mid = left + (right-left)/2;\n            \n            if(sum[mid]-sum[i] <= (sum[sz-1] - sum[i])/2) {\n                //possible ans\n                ans2 = mid;\n                left = mid+1;\n            } else {\n                right = mid-1;\n            }\n        }\n        return ans2;\n    }\n};\n```
[]