#include #include using namespace std; #define fi first #define se second #define int long long #define all(v) v.begin(), v.end() #define pb push_back #define rep(i, a, b) for (int i = a; i <= b; i++) //iota(first, last, 1); typedef long long ll; typedef unsigned long long ull; typedef pair ii; typedef pair sii; typedef pair iii; const int INF = 3e18; const long double EPS = 10e-9; const ll MOD = 1e9+7; signed main() { ios_base::sync_with_stdio(0); cin.tie(); cout.tie(); // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); int n, m; cin >> n >> m; vector l; for (int i=1; i<=n; i++) { int a; cin >> a; l.pb(a); } int ans = 0; for (int i=1; i<=m; i++) { int f, b, w; cin >> f >> b >> w; int x = b; auto itr = lower_bound(l.begin(), l.end(), f); if (itr != l.end()) { x = max(x, w - abs(f - *itr)); // c << *itr << " " << f << '\n'; } if (itr != l.begin()) { x = max(x, w - abs(f - *(--itr))); } // cout << *itr << " " << f << '\n'; ans += x; } cout << ans; return 0; }