-
Notifications
You must be signed in to change notification settings - Fork 1
/
10713.cpp
65 lines (53 loc) · 1.1 KB
/
10713.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <functional>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <cmath>
#define xx first
#define yy second
#define all(x) (x).begin(), (x).end()
using namespace std;
using i64 = long long;
using ii = pair<int, int>;
using ii64 = pair<i64, i64>;
int stack_[200005];
int main()
{
int n, m;
scanf("%d %d", &n, &m);
vector<int> p(m);
for (int i = 0; i < m; i++)
scanf("%d", &p[i]);
vector<i64> sum(n + 5);
for (int i = 0; i < m - 1; i++)
{
if (p[i] < p[i + 1])
{
sum[p[i]] += 1;
sum[p[i + 1]] += -1;
}
else
{
sum[p[i + 1]] += 1;
sum[p[i]] += -1;
}
}
for (int i = 1; i <= n; i++)
sum[i] = sum[i] + sum[i - 1];
i64 ans = 0;
for (int i = 1; i < n; i++)
{
int a, b, c;
scanf("%d %d %d", &a, &b, &c);
if (sum[i] != 0)
ans += min(a*sum[i], b*sum[i] + c);
}
printf("%lld\n", ans);
return 0;
}