官方题解给出的是 (O(tlog s)) 的解法,但实际上我们可以做到单次查询 (O(1)) 的 (O(t)) 做法.
同样是贪心,可以看出,我们每次花费 (10) 显然可以做到花费钱数最大化.
故 (mathbf{ans}= egin{cases} lfloor dfrac{s}{9}
floor imes 10 +smod 9-1,9|s \ lfloor dfrac{s}{9}
floor imes 10 +smod 9,
m Otherwise end{cases})
为什么在 (9|s) 的时候需要最后减去一个 (1) 呢?因为此时在最后一次操作时 (s) 仅会剩下 (9),如果仍然用 (lfloor dfrac{s}{9}
floor imes 10 +smod 9) 的话答案就会多出 (1),所以要将这个 (1) 减掉.
(然而可以用 (s+lfloor dfrac{s-1}{9}
floor) 或 (lfloor dfrac{10s}{9}
floor),比我写的强 (100) 倍...)
应该没有什么给代码的必要了吧...