algorithms – Even distribution of weighted sums across a period of time

I want to automatically&optimally split and distribute a number in several buckets as evenly as possible across a period of time.

Example:

  • 5000 across 12 months, in 6 buckets, with weights 15%, 20%, 15%, 10%, 30%, 10%, and a minimum of 100 per month per bucket; that is ~416 per month across buckets

Rules:

  • This is the catch: there has to be a minimum in each bucket (100 in our example; obviously, if this is zero, then the solution is very easy aka just an average)
  • Amount in each bucket doesn’t have to be a whole number
  • Weights must be respected
  • Each bucket may skip a month of two, just so the sum per month across buckets adds up to 416

An example of my manual effort
enter image description here

Generalization and nice-to-haves

  • Configurable number of buckets & number of periods
  • Configurable minimum amount per bucket per month

References