前言 / Foreword
非常好题目。非常好题目背景。
Great problem, great quote.
扽西 / Analysis
先考虑最优解长什么样子。如果先攻击再增加,并且可以把增加放到攻击前面,那么造成的伤害可以变多 。因此,一定要尽可能先增加再攻击。故而最优解一定形如,重复 次“增加 次,攻击 次”,再增加 次,攻击 次。这样花费了 枚金币,造成了 的伤害。
Consider what form the optimal solution can be in. If one firstly attacks the monster then increases , the damage dealt is less than that if one firstly increases then attakcs the monster. Therefore, in the optimal solution, the increments must be before attacks as much as possible, which means the optimal solution must be in the following form: repeat “increase for times, and attack once” for times, then increase for times, then attack times. In this way, damage of is dealt by costing coins.
,一看就很像根号分治的样子。考虑设立阈值 :
, which is super sqrt-balancing-ish. Consider a threshold :
若 ,因为 很小, 的范围为 也很小,可以直接考虑枚举 ,计算出最小的 更新答案。因为一旦 就可以不用再枚举了, 的范围是 的,因此这时的复杂度是 。
When , since is small, and the range of is to , one can enumerate , then calculate the least possible to update the answer. When already reaches , there’s no need to continue the enumeration anymore, so is in a range of , which implies a complexity of .
若 ,此时 很小。此时枚举 ,枚举 的范围是 的,再计算最小的 即可。因为调和级数,这部分的复杂度是 的。 时需要特殊用数论分块处理,因此总复杂度 。
When , is small. Therefore, is in a range of . By enumerating and , one can determine the least possible and then update the answer. Thanks to the harmonic series, The complexity is . However, when , one needs to use the trick of ” different values for ” to enumerate in a clever way. The total complexity is .
取 ,每组数据的时间复杂度是 ,可以通过。
Take , the time complexity per test is , which can pass the problem easily.