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;
|
|
|
|
|
#define int long long
|
|
|
|
|
#define endl "\n"
|
|
|
|
|
const int N = 100010;
|
|
|
|
|
int n, m; // 铁路途经n个城市,要去m个城市
|
|
|
|
|
int p[N]; // 记录经过站点的顺序
|
|
|
|
|
int a[N], b[N], c[N]; // 记录每段路径所花的费用
|
|
|
|
|
int t[N]; // 记录站点之间的路径经过的次数
|
|
|
|
|
int ans; // 答案
|
|
|
|
|
signed main() {
|
|
|
|
|
cin >> n >> m;
|
|
|
|
|
|
|
|
|
|
for (int i = 1; i <= m; i++) cin >> p[i];
|
|
|
|
|
for (int i = 1; i < n; i++) cin >> a[i] >> b[i] >> c[i];
|
|
|
|
|
|
|
|
|
|
// 所有的区间都以较小的点排在前面,例如:2-1,5-3都用1-2,3-5表示,
|
|
|
|
|
// 且每一段都用前面较小的点作为标记!!!!
|
|
|
|
|
for (int i = 1; i < m; i++) {
|
|
|
|
|
int x, y;
|
|
|
|
|
if (p[i] > p[i + 1]) {
|
|
|
|
|
x = p[i + 1];
|
|
|
|
|
y = p[i];
|
|
|
|
|
} else {
|
|
|
|
|
x = p[i];
|
|
|
|
|
y = p[i + 1];
|
|
|
|
|
}
|
|
|
|
|
t[x]++;
|
|
|
|
|
t[y]--;
|
|
|
|
|
}
|
|
|
|
|
for (int i = 1; i <= n; i++) t[i] += t[i - 1]; // 求前缀和
|
|
|
|
|
for (int i = 1; i <= n - 1; i++)
|
|
|
|
|
ans += min(a[i] * t[i], (b[i] * t[i] + c[i])); // 求总的最小就是把每一段的最小相加
|
|
|
|
|
cout << ans << endl;
|
|
|
|
|
}
|