I need to keep a set of five elements [a:b:c:d:e] in a ratio of [2:1:3:2:1].
I have a collection of [2035, 1050, 3060, 2040, 1027].
I need to take maximum amount of the elements according to ratio and keep the rest separately.
| ELEMENT | RATIO | TOTAL Collection | RATIO WISE QTY | REMAINDER |
|---|---|---|---|---|
| a | 2 | 2035 | ? | ? |
| b | 1 | 1050 | ? | ? |
| c | 3 | 3060 | ? | ? |
| d | 2 | 2040 | ? | ? |
| e | 1 | 1027 | ? | ? |
| ELEMENT | RATIO | TOTAL COLLECTION | RATIO WISE QTY | REMAINDER |
|---|---|---|---|---|
| a | 2 | 2035 | 2034 | 1 |
| b | 1 | 1050 | 1017 | 33 |
| c | 3 | 3060 | 3051 | 9 |
| d | 2 | 2040 | 2034 | 6 |
| e | 1 | 1027 | 1017 | 10 |
How can I build an algorithm to get the last two column value from the first three columns.

I think (until some one with a better idea comes along) - you essentially have an optimisation problem. To solve this in a naive way, would be to solve with a binary search, where you choose an upper boundary
where
best_unitary_valuewill then be equivalent to1017the condition could look like
If we have lots of values, then you can use regression with a condition on the output.