TITLE: How can I count solutions to $x_1 + \ldots + x_n = N$?
QUESTION [8 upvotes]: I am interested in how many non-negative integer solutions there are to:
$$x_1 + \ldots + x_N = B$$
where at least $K$ of the variables $x_1, \ldots , x_N \geq C$
For example when:
$B = 5, N = 3, K = 2, C = 2$
I want to count the solutions to:
$$x_1 + x_2 + x_3 = 5$$
where at least $2$ of the variables are $\geq 2$.
I found the total number of candidate solutions using the $\binom{B+N-1}{B} = 21$
However, only $9$ of them have two variables $\geq 2$.
\begin{align*}
    2+0+3& =5\\
    2+1+2& =5\\
    3+0+2& =5\\
    1+2+2& =5\\
    3+2+0& =5\\
    0+2+3& =5\\
    0+3+2& =5\\
    2+3+0& =5\\
    2+2+1& =5
\end{align*}
I feel there is a connection to the Associated Stirling numbers of the second kind. But I can't place it :(
EDIT:
Here is my code for enumerating them all to count the number of ways of select B elements from a set of N (uniformly with replacement), such that you have at least C copies of K elements - also shows the output for this question I'm asking here as it's the core piece. Obviously can't be run for very large values of the parameters - that's why I'm here :) Code is here
Here is another example for B = 6, N = 3, C = 2 and K = 2 there are 16 solutions:
\begin{align*}
0+2+4& = 6\\
0+3+3& = 6\\
0+4+2& = 6\\
1+2+3& = 6\\
1+3+2& = 6\\
2+0+4& = 6\\
2+1+3& = 6\\
2+2+2& = 6\\
2+3+1& = 6\\
2+4+0& = 6\\
3+0+3& = 6\\
3+1+2& = 6\\
3+2+1& = 6\\
3+3+0& = 6\\
4+0+2& = 6\\
4+2+0& = 6\\
\end{align*}
There are a number of different and correct solutions below. I don't know which to accept.

REPLY [4 votes]: A tailor-made approach by analytic combinatorics. The coefficient of $x^B$ in 
$$ \frac{1}{(1-x)^N} = \left(1+x+x^2+x^3+\ldots\right)^N $$
obviously counts the number of ways of representing $B$ as a sum of $N$ non-negative integers. By stars and bars, or by the (negative) binomial theorem, such number is $\binom{N+B-1}{N-1}$. We may use an extra variable to mark the terms with exponent $\geq C$, and consider:
$$ g(z,x) = \left(1+x+x^2+\ldots+x^{C-1}+ z x^{C}+z x^{C+1}+ z x^{C+2}+\ldots\right)^N $$
that is:
$$ g(z,x) = \left(\frac{1-x^C}{1-x}+z\cdot\frac{x^C}{1-x}\right)^N = \frac{(1+(z-1) x^C)^N}{(1-x)^N}.$$
Now the coefficient of $x^B$ in $g(z,x)$ is a polynomial in the $z$ variable, $h_B(z)$, and we are interested in summing the monomials of $h_B(z)$ whose degree is $\geq K$. That sum evaluated at $z=1$ gives the answer to our problem. However, I suspect there is no nice closed formula for summarizing the process, since even the computation of $h_B(z)$ involves a convolution. Are you fine with an integral representation of the answer? That is not hard to achieve through Cauchy's integral formula.
If $B=5,N=3, C=2$ and $K=2$, we have $h_B(z)=12z+\color{red}{9}z^2$, hence the answer is $\color{red}{9}$ as you checked. The general form of the answer is given by:

$$\begin{eqnarray*} [x^B]\sum_{D\geq K}[z^D]\frac{\left((1-x^C)+z x^C\right)^N}{(1-x)^N}&=&[x^B]\frac{1}{(1-x)^N}\sum_{D\geq K}\binom{N}{D}x^{CD}(1-x^C)^{N-D}\\&=&\sum_{D\geq K}\binom{N}{D}[x^{B-CD}]\frac{(1-x^C)^{N-D}}{(1-x)^N}\\&=&\color{red}{\sum_{D\geq K}\binom{N}{D}\sum_{h=0}^{N-D}\binom{N-D}{h}(-1)^h\binom{N+B-CD-Ch-1}{N-1}}, \end{eqnarray*}$$

rather ugly.