#include using namespace std; typedef long long ll; typedef long double ld; typedef pair Pll; typedef pair Pdd; template using MaxHeap = priority_queue; template using MinHeap = priority_queue, greater>; #define REP(i, n) for(int i = 0; i < n; i++) #define REPR(i, n) for(int i = n; i >= 0; i--) #define FOR(i, m, n) for(int i = m; i < n; i++) #define FORR(i, m, n) for(int i = m; i >= n; i--) #define INF (ll)1e17 #define ALL(v) v.begin(), v.end() #define SZ(x) ((ll)(x).size()) #define bit(n) (1LL<<(n)) #define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() ); #define cauto const auto& #define cdebug if (debug_mode) cerr #define dump(x) if (debug_mode) cerr << #x << " = " << (x) << "\t"; #define SP << " " << #define TB << "\t" << #ifdef _LOCAL bool debug_mode = true; #else bool debug_mode = false; #endif int main() { ll N, M; cin >> N >> M; vector L(N); REP(i, N) cin >> L[i]; ll ans = 0; REP(i, M) { ll pos, b, w; cin >> pos >> b >> w; ll s = b; auto itr = lower_bound(ALL(L), pos); if (itr != L.end()) { s = max(s, w - abs(*itr - pos)); } else if (itr != L.begin()) { s = max(s, w - abs(*prev(itr) - pos)); } ans += s; } cout << ans << endl; return 0; }