#P1251. 摆渡车(2018普及组)
摆渡车(2018普及组)
Description
有 <math xmlns="http://www.w3.org/1998/Math/MathML">nn 名同学要乘坐摆渡车从人大附中前往人民大学,第 <math xmlns="http://www.w3.org/1998/Math/MathML">ii 位同学在第 <math xmlns="http://www.w3.org/1998/Math/MathML">t_iti 分钟去 等车。只有一辆摆渡车在工作,但摆渡车容量可以视为无限大。摆渡车从人大附中出发、 把车上的同学送到人民大学、再回到人大附中(去接其他同学),这样往返一趟总共花费 <math xmlns="http://www.w3.org/1998/Math/MathML">mm 分钟(同学上下车时间忽略不计)。摆渡车要将所有同学都送到人民大学。
凯凯很好奇,如果他能任意安排摆渡车出发的时间,那么这些同学的等车时间之和最小为多少呢?
注意:摆渡车回到人大附中后可以即刻出发。
Input Format
第一行包含两个正整数 <math xmlns="http://www.w3.org/1998/Math/MathML">n, mn,m,以一个空格分开,分别代表等车人数和摆渡车往返一趟的时间。第二行包含 <math xmlns="http://www.w3.org/1998/Math/MathML">nn 个正整数,相邻两数之间以一个空格分隔,第 <math xmlns="http://www.w3.org/1998/Math/MathML">ii 个非负整数 <math xmlns="http://www.w3.org/1998/Math/MathML">t_iti 代表第 <math xmlns="http://www.w3.org/1998/Math/MathML">ii 个同学到达车站的时刻。
Output Format
输出一行,一个整数,表示所有同学等车时间之和的最小值(单位:分钟)。输入 #1
5 1
3 4 4 3 5
输出 #1
0
输入 #2
5 5
11 13 1 5 5
输出 #2
4
Hint
【输入输出样例 1 说明】
同学 <math xmlns="http://www.w3.org/1998/Math/MathML">1 和同学 <math xmlns="http://www.w3.org/1998/Math/MathML">4 在第 <math xmlns="http://www.w3.org/1998/Math/MathML">3 分钟开始等车,等待 <math xmlns="http://www.w3.org/1998/Math/MathML">0 分钟,在第 <math xmlns="http://www.w3.org/1998/Math/MathML">3 分钟乘坐摆渡车出发。摆渡车在第 <math xmlns="http://www.w3.org/1998/Math/MathML">4 分钟回到人大附中。
同学 <math xmlns="http://www.w3.org/1998/Math/MathML">2 和同学 <math xmlns="http://www.w3.org/1998/Math/MathML">3 在第 <math xmlns="http://www.w3.org/1998/Math/MathML">4 分钟开始等车,等待 <math xmlns="http://www.w3.org/1998/Math/MathML">0 分钟,在第 <math xmlns="http://www.w3.org/1998/Math/MathML">4 分钟乘坐摆渡车 出发。摆渡车在第 <math xmlns="http://www.w3.org/1998/Math/MathML">5 分钟回到人大附中。
同学 <math xmlns="http://www.w3.org/1998/Math/MathML">5 在第 <math xmlns="http://www.w3.org/1998/Math/MathML">5 分钟开始等车,等待 <math xmlns="http://www.w3.org/1998/Math/MathML">0 分钟,在第 <math xmlns="http://www.w3.org/1998/Math/MathML">5 分钟乘坐摆渡车出发。自此 所有同学都被送到人民大学。总等待时间为 <math xmlns="http://www.w3.org/1998/Math/MathML">0。
【输入输出样例 2 说明】
同学 <math xmlns="http://www.w3.org/1998/Math/MathML">3 在第 <math xmlns="http://www.w3.org/1998/Math/MathML">1 分钟开始等车,等待 <math xmlns="http://www.w3.org/1998/Math/MathML">0 分钟,在第 <math xmlns="http://www.w3.org/1998/Math/MathML">1 分钟乘坐摆渡车出发。摆渡 车在第 <math xmlns="http://www.w3.org/1998/Math/MathML">6 分钟回到人大附中。
同学 <math xmlns="http://www.w3.org/1998/Math/MathML">4 和同学 <math xmlns="http://www.w3.org/1998/Math/MathML">5 在第 <math xmlns="http://www.w3.org/1998/Math/MathML">5 分钟开始等车,等待 <math xmlns="http://www.w3.org/1998/Math/MathML">1 分钟,在第 <math xmlns="http://www.w3.org/1998/Math/MathML">6 分钟乘坐摆渡车 出发。摆渡车在第 <math xmlns="http://www.w3.org/1998/Math/MathML">11 分钟回到人大附中。
同学 <math xmlns="http://www.w3.org/1998/Math/MathML">1 在第 <math xmlns="http://www.w3.org/1998/Math/MathML">11 分钟开始等车,等待 <math xmlns="http://www.w3.org/1998/Math/MathML">2 分钟;同学 <math xmlns="http://www.w3.org/1998/Math/MathML">2 在第 <math xmlns="http://www.w3.org/1998/Math/MathML">13 分钟开始等车, 等待 <math xmlns="http://www.w3.org/1998/Math/MathML">0 分钟。他/她们在第 <math xmlns="http://www.w3.org/1998/Math/MathML">13 分钟乘坐摆渡车出发。自此所有同学都被送到人民大学。 总等待时间为 <math xmlns="http://www.w3.org/1998/Math/MathML">4。
可以证明,没有总等待时间小于 <math xmlns="http://www.w3.org/1998/Math/MathML">4 的方案。
【数据规模与约定】
对于 <math xmlns="http://www.w3.org/1998/Math/MathML">10% 的数据,<math xmlns="http://www.w3.org/1998/Math/MathML">n≤10,m=1,0≤ti≤100。
对于 <math xmlns="http://www.w3.org/1998/Math/MathML">30% 的数据,<math xmlns="http://www.w3.org/1998/Math/MathML">n≤20,m≤2,0≤ti≤100。
对于 <math xmlns="http://www.w3.org/1998/Math/MathML">50% 的数据,<math xmlns="http://www.w3.org/1998/Math/MathML">n≤500,m≤100,0≤ti≤104。
另有 <math xmlns="http://www.w3.org/1998/Math/MathML">20% 的数据,<math xmlns="http://www.w3.org/1998/Math/MathML">n≤500,m≤10,0≤ti≤4×106。
对于 <math xmlns="http://www.w3.org/1998/Math/MathML">100% 的数据,<math xmlns="http://www.w3.org/1998/Math/MathML">n≤500,m≤100,0≤ti≤4×106。
Source
动态规划相关
在下列比赛中: