How do I enumerate all $m$-tuples of positive integers $(a_1,...,a_m)$ subject to the following constraints?

For each $i$ in \${ 1,\ldots,m }\$, there is a number $n_i \geq 0$ such that $a_i \leq n_i$.

For each ordered pair $(i,j)$ with $i,j$ in \${ 1,\ldots ,m }\$, there are numbers $c_{ij}, d_{ij} \geq 0$ such that:

if $a_i > c_{ij}$, then $a_j \leq d_{ij}$.

$c_{ij} = c_{ji}$.

So far, I have come up with the following solution. Is there a more efficient way to do this?

```
for a[1]=0,...,n[1] do
{
for j=2,...,m do
{
if a[1] > c[1][j] then n[j]:=min{n[j],d[1][j]}
else n[j]:=n[j]
}
for a[2]=0,...,n[2] do
{
for j=3,...,m do
{
if a[2] > c[2][j] then n[j]:=min{n[j],d[2][j]}
else n[j]:=n[j]
}
for a[3]=0,...,n[3] do
{
.
.
.
for a[m]=0,...,n[m] do
{
print (a[1],...,a[m])
}
}...}}
```