#include using namespace std; using ll = long long; template using min_priority_queue = priority_queue, greater>; using pii = pair; using pll = pair; using Graph = vector>; const ll INF = 1LL << 60; template void chmax(T& a, T b) { if (b > a) a = b; } template void chmin(T& a, T b) { if (b < a) a = b; } template std::ostream& operator<<(std::ostream& os, const pair& x) noexcept { return os << "(" << x.first << ", " << x.second << ")"; } template void print_vector(vector a) { cout << '['; for (int i = 0; i < a.size(); i++) { cout << a[i]; if (i != a.size() - 1) { cout << ", "; } } cout << ']' << endl; } void solve() { ll N, M; cin >> N >> M; vector L(N); for (int i = 0; i < N; i++) { cin >> L[i]; } L.push_back(INF); L.push_back(-INF); sort(L.begin(), L.end()); ll ret = 0; for (int j = 0; j < M; j++) { ll f, b, w; cin >> f >> b >> w; auto it = lower_bound(L.begin(), L.end(), f); if (*it == f) { // もともと水中にいる ret += w; continue; } ll x = *prev(it); ll y = *it; ll z = min(y - f, f - x); ret += max(w - z, b); } std::cout << ret << "\n"; } int main() { ios::sync_with_stdio(false); std::cin.tie(nullptr); int T = 1; while (T--) { solve(); } return 0; }