Skip to content

Instantly share code, notes, and snippets.

@gedorinku
Last active January 8, 2016 13:07
Show Gist options
  • Save gedorinku/6f2aa21b4825b79fe2a8 to your computer and use it in GitHub Desktop.
Save gedorinku/6f2aa21b4825b79fe2a8 to your computer and use it in GitHub Desktop.
#include <bits/stdc++.h>
using namespace std;
#define int long long
static const int INF = 1LL<<61;
signed main() {
int n, m, cum[100005] = {0}, pre;
cin >> n >> m >> pre;
for (int i = 1; i < m; ++i) {
int p;
cin >> p;
int s = min(pre, p), t = max(pre, p);
cum[s]++;
cum[t]--;
pre = p;
}
int sum = 0, ans = 0;
for (int i = 1; i < n; ++i) {
sum += cum[i];
int a, b, c;
cin >> a >> b >> c;
if ((c / (a - b)) < sum) {
ans += sum * b + c;
} else {
ans += sum * a;
}
}
cout << ans << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment