#include using namespace std; using ll = long long; #define rep(i, s, e) for (int i = (int)s; i < (int)e; ++i) #define all(a) (a).begin(), (a).end() int main() { cin.tie(nullptr); int N, M; cin >> N >> M; vector L(N), F(M), B(M), W(M); rep(i, 0, N) cin >> L[i]; rep(i, 0, M) cin >> F[i] >> B[i] >> W[i]; ll ans = 0; rep(i, 0, M) { if (binary_search(all(L), F[i])) { ans += W[i]; continue; } int ind = lower_bound(all(L), F[i]) - L.begin(); ll left = LLONG_MAX, right = LLONG_MAX; if (ind != N) right = L[ind] - F[i]; if (ind != 0) left = F[i] - L[ind - 1]; ans += max(B[i], W[i] - min(right, left)); } cout << ans << '\n'; }