#include using namespace std; #define int long long #define pb push_back #define ppb pop_back #define mp make_pair #define fi first #define se second #define endl '\n' const int mod = 1e9+7; void solve(){ int n, m; cin >> n >> m; int pohon[n]; for (int i = 0; i < n; i++){ cin >> pohon[i]; } vector> ikan; for (int i = 0; i < m; i++){ int a, b, c; cin >> a >> b >> c; ikan.pb(make_tuple(a, b, c)); } int ans = 0; for (auto i:ikan){ int f = get<0> (i); int b = get<1> (i); int w = get<2> (i); int y = upper_bound(pohon, pohon+n, f)-pohon; if (y > n-1) y = n-1; int x = y-1; if (x < 0) x = 0; w = max(w-abs(f-pohon[x]), w-abs(f-pohon[y])); ans += max(b, w); } cout << ans << endl; } signed main (){ ios_base::sync_with_stdio(false); cin.tie(0); int t = 1; //cin >> t; while (t--){ solve(); } }