#include using namespace std; #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") typedef long long ll; const ll INF = 1e18; const ll MOD = 1e9 + 7; const ll MAXN = 2e5 + 5; const ll LOG = 100; #define vll vector #define pll pair #define fi first #define se second #define endl '\n' ll n, m; ll a [MAXN]; set st; pll b [MAXN]; void solve(){ cin >> n >> m; st.clear(); for(ll i = 1; i <= n; i++){ cin >> a[i]; st.insert(a[i]); } ll tot = 0; for(ll i = 1; i <= m; i++){ ll x, y, z; cin >> x >> y >> z; ll mn = INF; auto it = st.lower_bound(x); if(it != st.end()){ mn = min(mn, abs(*it - x)); } if(it != st.begin()){ it = prev(it); mn = min(mn, abs(*it - x)); } tot += y + max((ll)0, z-y-mn); } cout << tot << endl; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); // ll t; // cin >> t; // while(t--){ solve(); // } }