PaulRS and Gustav,

I think the preceding solution over-counts some of the arrangements by looking at ways to choose 2 boxes which contain exactly k balls and then multiplying by the number of ways to arrange at least k balls in the remaining boxes. The problem is that some of those arrangements will also include 2 boxes containing exactly k balls, and those arrangements are counted more than once.

So here is an alternative approach which I think avoids that difficulty. As before, first choose the three empty boxes, which can be done in

ways. We now want to count the number of ways in which r balls can be put into n-3 boxes so that at least 2 boxes contain exactly k balls and all boxes contain at least k balls. Call this number N.

To compute N, we count the number of ways to put r balls into n-3 boxes with at least k balls in each box and then subtract the number of arrangements which violate the "at least 2 boxes with exactly k balls" constraint. The unsatisfactory arrangements can be broken into two disjoint subsets: (1) those with no box containing k balls, so all the boxes contain at least k+1 balls; and (2) those with exactly one box containing k balls, and all the other boxes containing at least k+1 balls. Modifying PaulRS’s notation slightly, let

,

the number of ways to place k balls in n boxes with no constraints. Then the number of ways to put r balls into n-3 boxes with at least k balls in each box is

.

The number of ways to put r balls into n-3 boxes with at least k+1 balls in each box is

.

The number of ways to put k balls into one box and at least k+1 balls into each of the remaining boxes is

.

So

and the answer to the original problem is

.