// #pragma GCC optimize("O3,unroll-loops") // #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") #include "bits/stdc++.h" using namespace std; using ll = long long int; mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); int main() { ios::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; vector pos(n); for (int &x : pos) cin >> x; ll ans = 0; for (int i = 0; i < m; ++i) { int y, a, b; cin >> y >> a >> b; auto it = lower_bound(begin(pos), end(pos), y); int add = a; if (it != end(pos)) add = max(add, b - (*it - y)); if (it != begin(pos)) { --it; add = max(add, b - (y - *it)); } ans +=add; } cout << ans << '\n'; }