#include using namespace std; int main() { int N, M; cin >> N >> M; long long Ans = 0; vector L(N); for (int &a : L) cin >> a; for (int i = 0; i < M; i++) { int F, B, W; cin >> F >> B >> W; int it = lower_bound(L.begin(), L.end(), F) - L.begin(); if (it == 0) Ans += max(B, W - L.at(it) + F); else if (it == N) Ans += max(B, W - F + L.at(it - 1)); else Ans += max(B, max( W - L.at(it) + F, W - F + L.at(it - 1))); } cout << Ans << endl; }