Finding the Range of Solutions for KSum Variation
Suppose that the value at location $i$ is $j$. According to the continuity of $k$-sums (mentioned in an answer to the linked question), the range of possible sums of values at locations $1,\ldots,i-1$ is $$(i-1)a + \binom{i-1}{2},\ldots,(i-1)(j-1) - \binom{i-1}{2}.$$
Similarly, the range of possible sums of values at locations $i+1,\ldots,k$ is
$$
(k-i)(j+1) + \binom{k-i}{2}, \ldots, (k-i)b - \binom{k-i}{2}.
$$
Therefore the range of possible sums of all $k$ values is precisely
$$
(i-1)a + \binom{i-1}{2} + j + (k-i)(j+1) + \binom{k-i}{2}, \ldots, \\
(i-1)(j-1) - \binom{i-1}{2} + j + (k-i)b - \binom{k-i}{2}.
$$
We want to find for which values of $j$, the value $s$ is in this range. We get the following inequalities:
$$
(i-1)a + \binom{i-1}{2} + \binom{k-i+1}{2} + (k-i+1)j \leq s, \\
(k-i)b - \binom{i}{2} - \binom{k-i}{2} + ij \geq s.
$$
Therefore the range of $j$ is
$$
\max\left(\left\lceil \frac{s-(k-i)b + \binom{i}{2} + \binom{k-i}{2}}{i} \right \rceil,a+i-1\right) \leq j \leq \\
\min\left(\left\lfloor \frac{s - (i-1)a - \binom{i-1}{2} - \binom{k-i+1}{2}}{k-i+1} \right \rfloor,b-k+i\right).
$$