The question might be related more to math than to programming. I’ll explain the question by an example.
Let’s say I have an array with 100 items and I want to assign values to these items in such a way that the total of values in the first 80% of the items is 20% and the total of the values in the last 20% of the items is 80%. That is, the first 80% of the items get 20% and the rest get 80%. Knowing that the number of the items is determined at run time.
Is this possible?
Thanks.
Surely.
Let total be 1, than 80% is 0.8. If 20 items sum up to 0.8, each of them gets 0.8/20 = 0.04.
The rest 80 items get in total 0.2, each of them gets 0.2/80 = 0.01/4 = 0.0025.
The same applies for integers etc.