#abc252f. F - Bread

F - Bread

Score : 500500 points

问题描述

我们有一条长度为 LL 的面包,打算将其切割并分配给 NN 个孩子。 第 ii 个孩子(1iN1\leq i\leq N)希望得到长度为 AiA_i 的面包片。

现在,Takahashi 将重复以下操作以将面包切割成长度分别为 A1,A2,,ANA_1, A_2, \ldots, A_N 的面包片分给孩子:

选择一条长度为 kk 的面包,并在 11k1k-1(包括两端点)之间选择一个整数 xx。将这条面包切成长度分别为 xxkxk-x 的两条面包片。 不论 xx 的取值如何,这个操作的代价均为 kk

每个孩子 ii 必须精确收到长度为 AiA_i 的面包片,但允许留下一些未分配的面包片。

求解分配所有孩子面包所需的最小成本。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

We have a loaf of bread of length LL, which we will cut and distribute to NN children.
The ii-th child (1iN)(1\leq i\leq N) wants a loaf of length AiA_i.

Now, Takahashi will repeat the operation below to cut the loaf into lengths A1,A2,,ANA_1, A_2, \ldots, A_N for the children.

Choose a loaf of length kk and an integer xx between 11 and k1k-1 (inclusive). Cut the loaf into two loaves of length xx and kxk-x.
This operation incurs a cost of kk regardless of the value of xx.

Each child ii must receive a loaf of length exactly AiA_i, but it is allowed to leave some loaves undistributed.

Find the minimum cost needed to distribute loaves to all children.

Constraints

  • 2N2×1052 \leq N \leq 2\times 10^5
  • 1Ai1091\leq A_i\leq 10^9
  • A1+A2++ANL1015A_1+A_2+\cdots+A_N\leq L\leq 10^{15}
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN LL

A1A_1 A2A_2 \ldots ANA_N

Output

Print the minimum cost needed to distribute loaves to all children.

Sample Input 1

5 7
1 2 1 2 1

Sample Output 1

16

Takahashi can cut the loaf for the children as follows.

  • Choose the loaf of length 77 and x=3x=3, cutting it into loaves of length 33 and 44 for a cost of 77.
  • Choose the loaf of length 33 and x=1x=1, cutting it into loaves of length 11 and 22 for a cost of 33. Give the former to the 11-st child.
  • Choose the loaf of length 22 and x=1x=1, cutting it into two loaves of length 11 for a cost of 22. Give them to the 33-rd and 55-th children.
  • Choose the loaf of length 44 and x=2x=2, cutting it into two loaves of length 22 for a cost of 44. Give them to the 22-nd and 44-th children.

This incurs a cost of 7+3+2+4=167+3+2+4=16, which is the minimum possible. There will be no leftover loaves.

Sample Input 2

3 1000000000000000
1000000000 1000000000 1000000000

Sample Output 2

1000005000000000

Note that each child ii must receive a loaf of length exactly AiA_i.

update @ 2024/3/10 10:46:04