The task is to group a given string of text into sections according to various restrictions set on each section. Let's say we have a string S that is "Lorem ipsum dolorem." We also have 3 sections. Each section has restrictions that can place a restriction on the amount of the text that can be in the section. These restrictions can be specified in terms of number of characters or number of words. For example, the first section can have a minimum of five characters with a maximum of ten characters. The second section can have a minimum of one word with a maximum of five words, with each word being between 2 and 10 characters. The third section can have the same restriction as the first.
We need to use all available text, or else there is no grouping solution. Words cannot be separated (so we cannot break apart the a word into multiple part when grouping.) Solutions are better if we keep sentences together in the grouping, all other things equal.
What is the most efficient way to group the text?