Let $N = \sum n_i$ (omitting the indices of sums and products as they are obvious). It is enough to consider $x_i > 0$, and then instead of $P = \prod x_i^{n_i}$ , we may instead maximize the log of:
$$P \times \prod \left(\frac{a_i}{n_i}\right)^{n_i} = \prod\left(\frac{a_i}{n_i}x_i\right)^{n_i}$$
Now Jensen's inequality with the concave function $t \mapsto \log t$ immediately gives:
$$\sum n_i\log\left(\frac{a_i}{n_i} x_i\right) \leqslant N\log\left(\frac{\sum a_i x_i}N \right) = N\log\left(\frac{c}N \right)$$
Thus we get
$$P \times \prod \left(\frac{a_i}{n_i}\right)^{n_i} \leqslant \left(\frac{c}N \right)^N \implies P \leqslant \left(\frac{c}N \right)^N \prod \left(\frac{n_i}{a_i}\right)^{n_i}$$
with maximum when Jensen's inequality attains equality, i.e. when all $\dfrac{a_i x_i}{n_i}$ are equal.
It may be noted $n_i $ being positive reals is sufficient, need not be integers for this to work. Weighted AM-GM should also give the result for real $n_i > 0$, with careful choice of weights.