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
1008 B

2 years ago
#include <bits/stdc++.h>
using namespace std;
2 years ago
const int N = 100005;
2 years ago
#define int long long
#define endl "\n"
2 years ago
int p[N]; // 要访问的城市顺序
int a[N]; // 买票
int b[N]; // 充值
int c[N]; // 买卡
int q[N]; // 差分数组
int res;
// 数据范围是10^5*10^5,所以注意要开ll
2 years ago
signed main() {
2 years ago
int n, m;
2 years ago
cin >> n >> m;
2 years ago
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]; // 输入价格
2 years ago
2 years ago
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;
2 years ago
}
2 years ago
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;
2 years ago
}