Last active
January 8, 2016 13:07
-
-
Save gedorinku/6f2aa21b4825b79fe2a8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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