#include #include using namespace std; using namespace atcoder; using ll = long long; using ld = long double; using mint = modint998244353; int N, M; ll L[101010], F[101010], B[101010], W[101010]; int main() { cin >> N >> M; for (int i = 0; i < N; i++) cin >> L[i]; for (int i = 0; i < M; i++) cin >> F[i] >> B[i] >> W[i]; ll ans = 0; for (int i = 0; i < M; i++) { int pos1 = lower_bound(L, L + N, F[i]) - L; if (pos1 == 0) { if (abs(L[pos1] - F[i]) < W[i] - B[i]) ans += W[i] - abs(L[pos1] - F[i]); else ans += B[i]; } else if (pos1 == N) { if (abs(L[pos1 - 1] - F[i]) < W[i] - B[i]) ans += W[i] - abs(L[pos1 - 1] - F[i]); else ans += B[i]; } else { if (min(abs(L[pos1] - F[i]), abs(L[pos1 - 1] - F[i])) < W[i] - B[i]) ans += W[i] - min(abs(L[pos1] - F[i]), abs(L[pos1 - 1] - F[i])); else ans += B[i]; } } cout << ans << endl; return 0; }