Note that (for example) changing $~S~$ to $~7~$ permits the two solutions of $~(3,3,1)~$ and $~(3,2,2).~$
So, in situations where you are guaranteed that there is exactly one solution, the wiggle room must be small.
That is, the sum must be close to either the absolute minimum sum possible with the elements or absolute maximum sum possible with the elements.
You will be able to tell at a glance whether $~S~$ is close to the minimum or maximum.
So, assume (for purposes of illustration) that $~S~$ is close to the maximum. Then, start by considering $~S'~$ equal to the maximum sum possible. Then consider what you need to do to wiggle the sum, by decreasing it in the amount $~(S' - S).$
For example, in the specified problem, $~S' = 9 \implies (S' - S) = 1.$
The only way to wiggle the sum by decreasing it in the amount $~(S' - S) = 1,~$ is by changing on of the $~3$'s to a $~2.$
In the situation where there may or may not be multiple solutions, the situation is much more complicated. My first step would be to consider whether $~S~$ was close to the minimum, or close to the maximum. Again, for illustrative purposes, temporarily assume that $~S~$ is close to the maximum, and that there may or may not be more than one solution.
The procedure is roughly the same as in the first part of the answer. Set $~S'~$ equal to the maximum sum possible, compute the wiggle of $~(S' - S),~$ and then determine all of the possible ways of achieving such a wiggle.
With the more general problem, there are two possible complications. I will address each complication in its own section. The first complication is that $~S~$ may be nowhere near the minimum or maximum sum possible.
For example, consider the problem of
$N = 17, ~P = \{1,2,3,\cdots,50\}, ~S = 400.$
In effect, you want the number of solutions to
$~x_1 + \cdots + x_{17} = 400.$
$~x_1, \cdots, x_{17} \in \Bbb{Z^+}.$
$~x_1, \cdots, x_{17} \leq 51.$
This problem can be solved either by generating functions, which I am ignorant of, or by
[Stars and Bars + Inclusion-Exclusion]. For a blueprint of how to attack such problems via the second approach, SB+IE, see this answer.
Note that here, I am taking an unauthorized license, by assuming that the order of the values assigned to the variables is deemed relevant. That is, a solution where $~x_1 = 1, ~x_2 = 2,~$ is deemed distinct from a solution where $~x_1 = 2, ~x_2 = 1.~$
If this assumption is false, then the problem involves Partitioning a number into a fixed set of terms.
In all of the previous problems, the elements in $~P~$ were in arithmetic sequence, which facilitates an analytical approach. What if the elements are not in sequence?
For instance, suppose that
How many solutions are there?
I consider this last problem a nightmare, and I see no analytical approach to the problem.