P18090 [UKIEPC 2026] Mid Clocking

Description

A row of slots can hold processors. Each processor handles only one task and enters a busy-wait state after completing it, waiting for the next instruction. When a processor has no immediately adjacent processor on either side, it has sufficient cooling and can reach $100\%$ of its maximum speed. If it has $1$ immediately adjacent processor, it can reach only $60\%$ of its maximum speed. If it has $2$ immediately adjacent processors, it can reach only $30\%$ of its maximum speed. ![image.png](https://cdn.luogu.com.cn/upload/image_hosting/mhudd1fo.webp) *Figure M.1: Illustration of Sample 2.* All tasks start at $t=0$. Given the number of seconds each task requires when its processor runs at full speed, assign tasks to processors so that the last task finishes as early as possible.

Input Format

The input first gives the number of tasks $n$ and the number of processor slots $s$ ($1 \le n \le s \le 10^6$). Then $n$ integers follow, representing the times $t_i$ required by the tasks when their processors run at $100\%$ of their maximum speed ($1 \le t_i \le 10^9$), in seconds.

Output Format

Output the minimum time required to complete all tasks. The absolute or relative error of your output must not exceed $10^{-6}$.

Explanation/Hint

Translated by QwenWork