Approximate bin-packing?
I assume you want to put items $w_1$ to $w_{i_1}$ into the first bin, $w_{i_1+1}$ to $w_{i_2}$ into the second bin, etc. etc. The number n of bins is given. This can be done with something similar to dynamic programming.
Examine all possible choices for $_1$ and calculate the error from bin 1 for each of these choices.
Then examine all possible choices for $i_2$. For each $i_2$ pick all possible $i_1$ and pick one where the total error from bin 1 and bin 2 is as small as possible. For each $i_2$, remember which $i_1$ was used with it.
Then examine all possible choices for $i_3$ etc. For $i_n$ there is obviously only one choice, and you have the solution.
You will notice that you make quite a few stupid choices. If you have 10 bins, X = 100, and the sum of weights is 1,000 then puting items with very little weight or total weight over 200 into the first bin is likely stupid. To help with this we find a non-optimal solution with a greedy algorithm. Then we don't accept anything that must be worse than the greedy algorithm. In the example, if the greed algorithm finds a solution with error = 100, then we would never put less than 50 or more than 150 in weight into the first bin.