2834. 找出美丽数组的最小和
题目链接:2834. 找出美丽数组的最小和
代码如下:
cpp
//数学公式
//参考:https://leetcode.cn/problems/find-the-minimum-possible-sum-of-a-beautiful-array/solutions/2413304/o1-shu-xue-gong-shi-pythonjavacgo-by-end-xsxg
class Solution {
public:
int minimumPossibleSum(int n, int target)
{
long long m=min(target/2,n);
return (m*(m+1)+(n-m-1+target*2)*(n-m))/2%1'000'000'007;
}
};