# Find a vector B that minimizes |W-A*B|

I want to find a candidate vector $$B$$ that

$$\min|(W - A_i * B_i)|$$ $$a_i > 0,\ A_i=\{a_0,...,a_i\},\ B_i=\{-1,0,1\}^i$$

For example, given

$$W = 0.6,\quad A_4 = [0.1, 0.2, 0.4, 0.7]$$

$$B_4 = [1, -1, 0, 1]$$
I only get that by searching an entire tree (DFS, BFS). I tried with a ternary tree, but 0 value in vector $$B$$ shuffles the ascendant order.