Firstly, let me apologize for my unclear title. I don't know how to describe this. Here is more description.
Given a ratio
$$x = x_1 : x_2 : x_3 : \cdots : x_n$$
where $s = \sum x_i$ and $x_i, n \in \mathbb{Z}^+$
Given $t$, is there any way to find the following ratio?
$$y = y_1 : y_2 : y_3 : \cdots : y_n$$ Such that
- $y$ is closest to $x$ (see below)
- $t = \sum y_i$
- $y_i \in \mathbb{Z}^+$
I would say $y$ is closest to $x$, if and only if, there is no other ratio
$$z = z_1 : z_2 : z_3 : \cdots : z_n$$
where $\sum z_i = t$ and $z_i \in \mathbb{Z}^+$
Such that:
$$\sum|\frac{z_i}{t} - \frac{x_i}{s}| < \sum|\frac{y_i}{t} - \frac{x_i}{s}|$$
My intuitive possible solution is: $$y_i = t \times \operatorname{round}(x_i \div s)$$
However, this is obviously stupid. Take the ratio $1:1$, and let's say we are looking for $t=5$.
Then following my proposal:
$$ x = 1:1\\ y = (5 \times \operatorname{round}(0.5)):(5 \times \operatorname{round}(0.5)) = 5:5 $$
Obviously, since $5+5= 10 \neq 5$, it violates my requirement $\sum y_i = t$. The correct answer of this example should be $2:3$ or $3:2$.
Thanks in advance.