menu ZJOJ
account_circle 请登录
home
首页
book
题目
apps
分类
play_circle_outline
状态
assessment
竞赛
assignment
作业
equalizer
排名
assignment_ind
登录
person_add
注册
1558: 海底高铁
时间限制:1.000s
内存限制:128MB

题目描述

该铁路经过 lns="http://www.w3.org/1998/Math/MathML">N 个城市,每个城市都有一个站。不过,由于各个城市之间不能协调好,于是乘车每经过两个相邻的城市之间(方向不限),必须单独购买这一小段的车票。第 lns="http://www.w3.org/1998/Math/MathML">i 段铁路连接了城市 lns="http://www.w3.org/1998/Math/MathML">i 和城市 lns="http://www.w3.org/1998/Math/MathML">i+1(1\leq i<N)。如果搭乘的比较远,需要购买多张车票。第 lns="http://www.w3.org/1998/Math/MathML">i 段铁路购买纸质单程票需要 lns="http://www.w3.org/1998/Math/MathML">A_i 博艾元。

虽然一些事情没有协调好,各段铁路公司也为了方便乘客,推出了 IC 卡。对于第 lns="http://www.w3.org/1998/Math/MathML">i 段铁路,需要花 lns="http://www.w3.org/1998/Math/MathML">C_i 博艾元的工本费购买一张 IC 卡,然后乘坐这段铁路一次就只要扣 lns="http://www.w3.org/1998/Math/MathML">B_i(B_i<A_i) 元。IC 卡可以提前购买,有钱就可以从网上买得到,而不需要亲自去对应的城市购买。工本费不能退,也不能购买车票。每张卡都可以充值任意数额。对于第 lns="http://www.w3.org/1998/Math/MathML">i 段铁路的 IC 卡,无法乘坐别的铁路的车。

小紫现在需要出差,要去 lns="http://www.w3.org/1998/Math/MathML">M 个城市,从城市 lns="http://www.w3.org/1998/Math/MathML">P_1 出发分别按照 lns="http://www.w3.org/1998/Math/MathML">P_1,P_2,P_3,\cdots,P_M 的顺序访问各个城市,可能会多次访问一个城市,且相邻访问的城市位置不一定相邻,而且不会是同一个城市。

现在他希望知道,出差结束后,至少会花掉多少的钱,包括购买纸质车票、买卡和充值的总费用。

输入格式

第一行两个整数,lns="http://www.w3.org/1998/Math/MathML">N,M

接下来一行,lns="http://www.w3.org/1998/Math/MathML">M 个数字,表示 lns="http://www.w3.org/1998/Math/MathML">P_i

接下来 lns="http://www.w3.org/1998/Math/MathML">N-1 行,表示第 lns="http://www.w3.org/1998/Math/MathML">i 段铁路的 lns="http://www.w3.org/1998/Math/MathML">A_i,B_i,C_i

输出格式

一个整数,表示最少花费

样例输入 content_copy

9 10
3 1 4 1 5 9 2 6 5 3
200 100 50
300 299 100
500 200 500
345 234 123
100 50 100
600 100 1
450 400 80
2 1 10

样例输出 content_copy

6394

提示/说明

 到 lns="http://www.w3.org/1998/Math/MathML">3 以及 lns="http://www.w3.org/1998/Math/MathML">8 到 lns="http://www.w3.org/1998/Math/MathML">9 买票,其余买卡。

对于 lns="http://www.w3.org/1998/Math/MathML">30\% 数据 lns="http://www.w3.org/1998/Math/MathML">M=2

对于另外 lns="http://www.w3.org/1998/Math/MathML">30\% 数据 lns="http://www.w3.org/1998/Math/MathML">N\leq1000,M\leq1000

对于 lns="http://www.w3.org/1998/Math/MathML">100\% 的数据 lns="http://www.w3.org/1998/Math/MathML">M,N\leq 10^5,A_i,B_i,C_i\le10^5

分类