code
class Solution {
public int minimumPossibleSum(int n, int target) {
final int mod = (int) 1e9 + 7;
int m = target / 2;
if (n <= m) {
return (int) ((1L + n) * n / 2 % mod);
}
long a = (1L + m) * m / 2 % mod;
long b = ((1L * target + target + n - m - 1) * (n - m) / 2) % mod;
return (int) ((a + b) % mod);
}
}
参考了答案,自己写的超时了
原文链接: https://blog.csdn.net/qq_53568730/article/details/136572553