#include using namespace std; #define ll long long #define fi first #define sec second #define pairz pair #define pb push_back ll tc = 1; const ll INF = 1e18; const ll N = 1e6+5; const ll MOD = 1e9 + 7; // thy will, not mine, be done. void input(){ ll n,m; cin >> n >> m; setst; for(int i=1;i<=n;i++){ ll x; cin >> x; st.insert(x); } ll ans = 0; for(int i=1;i<=m;i++){ ll f,b,w; cin >> f >> b >> w; auto x = st.lower_bound(f); auto y = x; if(x == st.end()) --y; if(x != st.begin()) --x; if(*y == f) ans += w; else{ ans += max({b, w - abs(f - *y), w - abs(f - *x)}); } } cout << ans << endl; } int main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); // cin >> tc; while(tc--) input(); } /* usahain clean code, jangan ribet2 implementasinya 11 + 14 + 8 = 33 2023 - 2013 2 */