Writing a list in format {m[1],0,a1},...{m[k],1,ak}

I need to write something as {m1,0,a1},…{m[k],1,ak}

You have to play with the order of evaluation. Here is a way:

Clear[p];
p[n_, k_] := Apply[Sum,
  {IntegerPart[(2 + n -
       Sum[i  m[i], {i, 3, k}])/2],
   Sequence @@ Table[
     {m[k - l],
      IntegerPart[(k - l)/k],
      (n - Sum[(s)  m[s],
          {s, k - l + 1, k}])/(k - l)},
     {l, 0, k - 3}]}]

Thank you very much. You introduce me at another level of programation.
Happiness