Kotlin Heroes: Episode 10 |
---|
Finished |
There is a staircase consisting of $$$n$$$ steps. Each step is either intact, or broken. For each broken step, an integer $$$a_i$$$ is given denoting the difficulty of repairing it.
Every day, you can either:
You want to repair all broken steps of the staircase, and you want to do it in the minimum possible number of days. What is the minimum total effort it will take to repair all broken steps in the minimum number of days?
The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases.
Each test case consists of two lines:
Additional constraint on the input: the sum of values of $$$n$$$ does not exceed $$$3 \cdot 10^5$$$.
For each test case, print one integer — the minimum possible total effort it will take to repair all broken steps in the minimum number of days.
650 0 0 0 040 13 15 8413 15 0 881 2 3 4 5 6 7 8599999999 100000000 99999999 99999999 9999999952 3 4 3 2
0 59 64 72 899999993 24
In the first test case, you don't have to do anything.
In the second test case, you can repair the $$$3$$$-rd and the $$$4$$$-th step during the first day, and the $$$2$$$-nd step during the second day. The total effort will be $$$2 \cdot (15 + 8) + 13 = 59$$$.
In the third test case, you can repair the $$$4$$$-th step during the first day, and two first steps during the second day. The total effort will be $$$8 + 2 \cdot (13 + 15) = 64$$$.
Name |
---|