#include using namespace std::literals::string_literals; using i64 = std::int_fast64_t; using std::cerr; using std::cin; using std::cout; using std::endl; #if defined(DONLINE_JUDGE) #define NDEBUG #elif defined(ONLINE_JUDGE) #define NDEBUG #endif template std::vector make_v(size_t a) { return std::vector(a); } template auto make_v(size_t a, Ts... ts) { return std::vector(ts...))>(a, make_v(ts...)); } int main() { int n, m; scanf("%d%d", &n, &m); std::vector l(n); for (auto &v : l) scanf("%d", &v); std::vector f(m), b(m), w(m); for (int i = 0; i < m; ++i) scanf("%d%d%d", &f[i], &b[i], &w[i]); std::vector ord(m); std::iota(ord.begin(), ord.end(), 0); std::sort(ord.begin(), ord.end(), [&](int i, int j) { return f[i] < f[j]; }); i64 ans = std::accumulate(b.begin(), b.end(), 0LL); int j = 0; for (int i : ord) { while (j < n and l[j] <= f[i]) ++j; if (j < n and l[j] == f[i]) continue; int near = 1 << 30; if (j < n) near = std::min(near, l[j] - f[i]); if (j - 1 >= 0) near = std::min(near, f[i] - l[j - 1]); const int prev = b[i]; const int next = w[i] - near; if (next > prev) ans += next - prev; } printf("%lld\n", ans); return 0; }