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.

35 lines
1.2 KiB

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