{"problem":{"name":"Bread","description":{"content":"We have a loaf of bread of length $L$, which we will cut and distribute to $N$ children.   The $i$\\-th child $(1\\leq i\\leq N)$ wants a loaf of length $A_i$. Now, Takahashi will repeat the operation be","description_type":"Markdown"},"platform":"AtCoder","limit":{"time_limit":2000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"abc252_f"},"statements":[{"statement_type":"Markdown","content":"We have a loaf of bread of length $L$, which we will cut and distribute to $N$ children.  \nThe $i$\\-th child $(1\\leq i\\leq N)$ wants a loaf of length $A_i$.\nNow, Takahashi will repeat the operation below to cut the loaf into lengths $A_1, A_2, \\ldots, A_N$ for the children.\n\n> Choose a loaf of length $k$ and an integer $x$ between $1$ and $k-1$ (inclusive). Cut the loaf into two loaves of length $x$ and $k-x$.  \n> This operation incurs a cost of $k$ regardless of the value of $x$.\n\nEach child $i$ must receive a loaf of length exactly $A_i$, but it is allowed to leave some loaves undistributed.\nFind the minimum cost needed to distribute loaves to all children.\n\n## Constraints\n\n*   $2 \\leq N \\leq 2\\times 10^5$\n*   $1\\leq A_i\\leq 10^9$\n*   $A_1+A_2+\\cdots+A_N\\leq L\\leq 10^{15}$\n*   All values in input are integers.\n\n## Input\n\nInput is given from Standard Input in the following format:\n\n$N$ $L$\n$A_1$ $A_2$ $\\ldots$ $A_N$\n\n[samples]","is_translate":false,"language":"English"}],"meta":{"iden":"abc252_f","tags":[],"sample_group":[["5 7\n1 2 1 2 1","16\n\nTakahashi can cut the loaf for the children as follows.\n\n*   Choose the loaf of length $7$ and $x=3$, cutting it into loaves of length $3$ and $4$ for a cost of $7$.\n*   Choose the loaf of length $3$ and $x=1$, cutting it into loaves of length $1$ and $2$ for a cost of $3$. Give the former to the $1$\\-st child.\n*   Choose the loaf of length $2$ and $x=1$, cutting it into two loaves of length $1$ for a cost of $2$. Give them to the $3$\\-rd and $5$\\-th children.\n*   Choose the loaf of length $4$ and $x=2$, cutting it into two loaves of length $2$ for a cost of $4$. Give them to the $2$\\-nd and $4$\\-th children.\n\nThis incurs a cost of $7+3+2+4=16$, which is the minimum possible. There will be no leftover loaves."],["3 1000000000000000\n1000000000 1000000000 1000000000","1000005000000000\n\nNote that each child $i$ must receive a loaf of length exactly $A_i$."]],"created_at":"2026-03-03 11:01:14"}}