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.

34 lines
1.2 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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