#include using namespace std; #define ll long long #define all(x) x.begin(),x.end() #define rep(i,a,b) for(int i=a;i<=b;i++) #define each(a,x) for (auto& x: a) const char nl = '\n'; void solve(){ int n,m; cin >> n >> m; vector l(n); each(l,x) cin >> x; ll ans = 0; for (int i = 0; i < m; i++){ int f,b,w; cin >> f >> b >> w; int cur = INT_MAX; auto it = lower_bound(all(l),f); if (it != l.end()) cur = min(cur, *it - f); if (it != l.begin()) cur = min(cur, f - *(--it)); ans += max(b, w - cur); } cout << ans << nl; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int t = 1; //cin >> t; while (t--){ solve(); } }