I think it should is `k -= weights[i-1]`, the k is the bp remaining weight 