composition of an integer number into some limited parts Given $k,m,n\in\mathbb N$, $n\ge m$, is there a way to find the "leading solution" with respect to the reverse lexicographic order for the following problem?
$$\left\{\begin{array}{ll} \sum_{i=0}^{k} a_i = m   \\ \sum_{i=0}^{k} (i+1) a_i = n \end{array}\right.$$
By the leading solution with respect to the reverse lexicographic order I mean the solution $(a_1,\dots,a_k)\in (\mathbb N\cup \{0\})^k$ that is the largest tuple which respect to this order in a point-wise comparation. 
Remark: Due to a previous que link, it is possible to determine the largest index $j$ such that $a_j\ne 0$.
So, the question here remains for $k<  n-m$.
 A: I am attempting to answer this with a "greedy" approach. I may be wrong in my logic, so please correct me if I am. At a high level, my approach is to first maximise lexicographically for the sum to $n$ and then "nudge" this sum into shape so that the sum to $m$ is satisfied. For this, let's define $S_n = \sum_{i=0}^{k} (i+1) a_i$ and $S_m = \sum_{i=0}^{k} a_i$. We want both $S_n = n$ and $S_m = m$ for some $a = (a_0, a_1, \dots, a_k)$, which is maximised according to reverse lexicographical ordering.
Step 1: We want the maximum $a$ for $S_n = n$. Construct $a$ easily as follows. Take $a_k = \lfloor \frac{n}{k + 1} \rfloor$. Then let $r$ be the remainder of the division and find the largest $j$ such that the followoing is non-zero: $a_j = \lfloor \frac{r}{j + 1} \rfloor$. Then take the remainder from that, and so on, until you are left with remainder $0$ or you end up "dumping" all the remainder in $a_0$. Now $S_n = n$ but it may be that $S_m < m$.
Step 2: If the above step left us with $S_m < m$, then we need to modify $a$ by making it smaller, so that $S_m = m$, such that our modification preserves $S_n = n$. Call the new vector $a'= (a_0', a_1', \dots, a_k')$. We still want the maximum such $a'$, so naturally we want to pick the lowest $i$ such that we must decrease $a_i$. To find this, again proceed greedily as follows. Set $a_1' := 0$ and $a_0' := a_0 + 2a_1$. This increases $S_m$ by $a_1$ and preserves $S_n$. Continue by setting $a_2' := 0$ and $a_0' := a_0' + 3a_2$ etc. until eventually $S_m \geq m$. If $S_m > m$, we've gone too far, and we simply "correct" our last step, which I'll sketch in the next step.
Step 3: Suppose in the process of step 2 we end up with $S_m > m$. Then there is some $a_i$ such that $i \times a_i$ pushed the sum over the edge. So in this case, we correct by first incrementing $a_i'$ and decrementing $a_0$ until just before $S_m \leq m$ again. Then we do the same for $a_{i - 1}'$, $a_{i - 2}'$ etc. until $S_m = m$. This phase is a bit fuzzy but I believe it will work, it just needs the details worked out a bit better.
Of course, we may get lucky and never have to do steps 2 and 3. I realise that this is an algorithm rather than a mathematical answer, and furthermore I have not proved that my constructed vector is indeed lexicographically maximal. But I believe this is a step in the right direction.
