1508. Range Sum of Sorted Subarray Sums
class Solution {
public:
int rangeSum(vector<int>& nums, int n, int left, int right)
{
vector<int> rangeSum;
for (int i = 0; i < nums.size(); i++)
{
int sum = 0;
for (int j = i; j < nums.size(); j++)
{
sum += nums[j];
rangeSum.push_back(sum);
}
}
sort(rangeSum.begin(), rangeSum.end());
int res = 0;
const int MOD = 1e9 + 7;
for (int i = left - 1; i < right; i++)
{
res = (res + rangeSum[i]) % MOD;
}
return res;
}
};
- T:
- S: