Comments

Great!

Because the inequality I wrote abode. $$$\frac{a + b}{k} + k \ge 2 \times \sqrt{a + b}$$$, and when $$$\frac{a + b}{k} = k$$$ the equality takes.

It's not difficult. You should just know the answer is $$$\lceil\frac{a}{k}\rceil + \lceil\frac{b}{k}\rceil + (k - 1)$$$ when you add your feet to k long. Then if you remove the ceil, you can get $$$\frac{a + b}{k} + k - 1$$$, it's just an inequality $$$a + b \ge 2 \times \sqrt{a \times b}$$$ when $$$a = b$$$ the equality is achieved. Therefore, for this function, it's $$$\frac{a + b}{k} = k$$$, .i.e $$$k^2 = a + b$$$. So $$$k = \sqrt{a + b}$$$, you can get the smallest value. However, you remove the ceil, so there maybe 2 off the correct answer. You should check around. Anyway, 1e5 is enough.

Maybe my code can help.199651953

First, there is something wrong in your if (n == 2). Then, maybe your solution ans+=tmp[j]*X, X+=2; is wrong.

You can remove the unnecessary special judgement, and reverse the vector dimension for convenience. As you did, you can sort and then let sum be the prefix sum and when get the answer for $$$j^{th}$$$ person, just ans += v[i][j] * j - sum.

Sorry for my poor English. :)

I still don't know why unordered_map will TLE in problem E = =