The problem
We define "$m$-cube" as an $m$-dimensional hypercube. ($m=2$ is square, $m=3$ is cube, ...)
$(\mathbf Q):$ Given a container $m$-cube of integer side length $a$, and $n$ many $m$-cubes of integer side lengths $1\lt a_1,a_2,\dots,a_n\lt a$, determine if we can fit all of them into the container such that the remaining empty space is fully filled with unit $m$-cubes.
You can assume that the given lengths of sides are sorted: $a_1\ge a_2 \ge \dots a_n \ge 2$.
I'm looking for references to known algorithms that can be applied here.
Motivation: the problem "For what natural n does there exist a cube composed of n cubes and more" can be reduced to sets of $(\mathbf Q)$ problems.
So far I know that if $m=1$ or $n\le 2^m$, we can answer $(\mathbf Q)$ in $O(n)$ time. (See below.)
Case $(n\in\mathbb N, m=1)$ and case $(n\le2^m,m\ge 2)$
Since $a$-side $m$-cube has at most $a^m$ unit cubes, we have the least necessary condition:
$$\sum_{i=1}^{n}a_i^m\le a^m \tag{$\mathbf n_1$}$$
If $m=1$, we have a $1$-cube which is a segment. In this case, $(\mathbf n_1)$ is a sufficient condition.
That is, if $m=1$ then $(\mathbf Q)$ can be answered true if and only if $(\mathbf n_1)$ holds.
From now on, assume $m\ge 2$. WLOG assume $a_{\text{max}}=a_1\ge a_2 \ge \dots \ge a_n\ge 2$.
It is not hard to consider placing $m$-cubes in corners of the container, to conclude:
$$ (\forall i\in\{2,3,\dots,n\})(a_i\le a-a_1) \tag{$\mathbf n_2$}$$
After placing the largest (side length $a_1$) $m$-cube in the (side length $a$) container $m$-cube, any next $m$-cube can't be larger than $a-a_1-j$ where $j\ge 0$ is the minimal distance from the placed $m$-cube and any of the sides of the container. To minimize $j$ (and maximize allowed space for next $m$-cube), we place the $a_1$ into any of the $2^m$ corners of the container $m$-cube.
If $n\le 2^m$, then $(\mathbf n_2)$ is a sufficient condition. (Place the $m$-cubes in the corners).
That is, If $n\le 2^m$ then $(\mathbf Q)\iff(\mathbf n_2)$. From now on, we can assume $n\ge 2^m+1,m\ge 2$.
The question now is, how to continue with this analysis further?
Can we find necessary and sufficient conditions for more general cases?