題目:
問你subarray的和sort之後
left到right加起來是多少
思路:
照做
把subarray 通通弄出來之後
sort加起來
姆咪
```cpp
class Solution {
public:
int rangeSum(vector<int>& nums, int n, int left, int right)
{
vector<int> sum(n,0);
vector<int> paper(n * (n + 1) / 2 , 0);
sum[0] = nums[0];
for(int i = 1 ; i < n ; i ++)
{
sum[i]+=sum[i-1];
sum[i]+=nums[i];
}
int p = 0;
for(int i = 0 ; i < n ; i ++)
{
paper[p] = sum[i];
p++;
for(int j = i+1 ; j < n ; j ++)
{
paper[p] = sum[j] - sum[i];
p++;
}
}
sort(paper.begin() , paper.end());
int res = 0;
for(int i = left -1 ; i < right ; i ++)
{
res += paper[i];
res %= 1000000007;
}
return res;
}
};
```