#include using namespace std; typedef long long int ll; typedef unsigned long long ull; typedef long double ld; int dx[8] = { 1, 0, -1, 0, 1, 1, -1, -1 }, dy[8] = { 0, 1, 0, -1, 1, -1, 1, -1 }; const long long mod = 998244353; const ll inf = 1LL << 60; const int INF = 5e8; int main() { int n, m; cin >> n >> m; vector l(n); for (int i = 0; i < n; i++) cin >> l[i]; ll ans = 0; for (int i = 0; i < m; i++) { int f, b, w; cin >> f >> b >> w; auto it = lower_bound(l.begin(), l.end(), f); if (it == l.begin()) { ans += max(b, -(l[0] - f) + w); } else if (it == l.end()) { ans += max(b, -(f - l[n - 1]) + w); } else { ans += max({ b, -(*it - f) + w, -(f - *prev(it)) + w }); } } cout << ans << endl; }