Comments

Problem B wa3 because I break when answer is greater than last answer.

Wrong Code

Then I printed all answer, and found that although the answer curve "looks like" go down and go up, but sometimes $$$ans(i) = ans(i-1) + 1$$$ while the curve is "going down"!

[deleted] Oh, my method is the same with editorial.