#include using namespace std; #define ll long long #define endl "\n" const int N = 1e5 + 5; int n, m; ll koor[N]; int binserbig ( int y ){ int l = 1, r = n, rec = -1; while ( l <= r ){ int mid = ( l + r ) / 2; if ( koor[mid] <= y ){ l = mid + 1; rec = mid; } else r = mid - 1; } return rec; } int binsersmall ( int y ){ int l = 1, r = n, rec = -1; while ( l <= r ){ int mid = ( l + r) / 2; if ( koor[mid] >= y ){ r = mid - 1; rec = mid; } else l = mid + 1; } return rec; } signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> m; for ( int i = 1; i <= n; i++) cin >> koor[i]; ll ans = 0; for ( int i = 1; i <= m; i++){ ll k, un, nun; cin >> k >> un >> nun; // nun -> dibawah pohon int idxbigger = binserbig ( k ); int idxsmaller = binsersmall ( k ); ll temp = un; if ( idxbigger != -1 ){ temp = max ( nun - abs ( koor[idxbigger] - k), temp); } if ( idxsmaller != -1 ){ temp = max ( nun - abs ( koor[idxsmaller] - k), temp); } ans += temp; } cout << ans << endl; }