#abc252f. F - Bread
F - Bread
Score : points
问题描述
我们有一条长度为 的面包,打算将其切割并分配给 个孩子。 第 个孩子()希望得到长度为 的面包片。
现在,Takahashi 将重复以下操作以将面包切割成长度分别为 的面包片分给孩子:
选择一条长度为 的面包,并在 和 (包括两端点)之间选择一个整数 。将这条面包切成长度分别为 和 的两条面包片。 不论 的取值如何,这个操作的代价均为 。
每个孩子 必须精确收到长度为 的面包片,但允许留下一些未分配的面包片。
求解分配所有孩子面包所需的最小成本。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
We have a loaf of bread of length , which we will cut and distribute to children.
The -th child wants a loaf of length .
Now, Takahashi will repeat the operation below to cut the loaf into lengths for the children.
Choose a loaf of length and an integer between and (inclusive). Cut the loaf into two loaves of length and .
This operation incurs a cost of regardless of the value of .
Each child must receive a loaf of length exactly , but it is allowed to leave some loaves undistributed.
Find the minimum cost needed to distribute loaves to all children.
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
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 and , cutting it into loaves of length and for a cost of .
- Choose the loaf of length and , cutting it into loaves of length and for a cost of . Give the former to the -st child.
- Choose the loaf of length and , cutting it into two loaves of length for a cost of . Give them to the -rd and -th children.
- Choose the loaf of length and , cutting it into two loaves of length for a cost of . Give them to the -nd and -th children.
This incurs a cost of , 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 must receive a loaf of length exactly .
update @ 2024/3/10 10:46:04