You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
#include <bits/stdc++.h>
|
|
|
|
using namespace std;
|
|
|
|
const int N = 100005;
|
|
|
|
#define int long long
|
|
|
|
#define endl "\n"
|
|
|
|
int p[N]; // 要访问的城市顺序
|
|
|
|
int a[N]; // 买票
|
|
|
|
int b[N]; // 充值
|
|
|
|
int c[N]; // 买卡
|
|
|
|
int q[N]; // 差分数组
|
|
|
|
int res;
|
|
|
|
|
|
|
|
// 数据范围是10^5*10^5,所以注意要开ll
|
|
|
|
signed main() {
|
|
|
|
int n, m;
|
|
|
|
cin >> n >> m;
|
|
|
|
for (int i = 0; i < m; i++) cin >> p[i]; // 记录访问顺序
|
|
|
|
for (int i = 1; i <= n - 1; i++) cin >> a[i] >> b[i] >> c[i]; // 输入价格
|
|
|
|
|
|
|
|
for (int i = 1; i < m; i++) { // 起点到终点,差分修改
|
|
|
|
int t1 = p[i - 1];
|
|
|
|
int t2 = p[i];
|
|
|
|
if (t1 > t2)
|
|
|
|
q[t2] += 1, q[t1] -= 1;
|
|
|
|
else
|
|
|
|
q[t1] += 1, q[t2] -= 1;
|
|
|
|
}
|
|
|
|
for (int i = 1; i <= n; i++) q[i] += q[i - 1]; // 前缀和处理
|
|
|
|
|
|
|
|
// 判断一下 n*a[i]和n*b[i]+c[i]的大小
|
|
|
|
for (int i = 1; i < n; i++)
|
|
|
|
res += min(q[i] * a[i], q[i] * b[i] + c[i]);
|
|
|
|
|
|
|
|
cout << res << endl;
|
|
|
|
}
|