#include #include #include using namespace std; using ll = long long; int main(){ int n, m; cin >> n >> m; vector l(n); for(auto &it: l) cin >> it; vector f(m), b(m), w(m); for(int i = 0; i < m; i++) cin >> f[i] >> b[i] >> w[i]; ll ans = 0; for(int i = 0; i < m; i++){ int ac = -1, wa = n; while(wa-ac > 1){ int wj = (wa+ac)/2; (l[wj] <= f[i] ? ac : wa) = wj; } int res = b[i]; if(0 <= ac && f[i] == l[ac]){ res = w[i]; }else{ if(0 <= ac) res = max(res, w[i]-abs(f[i]-l[ac])); if(wa < n) res = max(res, w[i]-abs(f[i]-l[wa])); } ans += res; } cout << ans << endl; return 0; }