/* -*- coding: utf-8 -*- * * 2408.cc: No.2408 Lakes and Fish - yukicoder */ #include #include using namespace std; /* constant */ const int MAX_N = 100000; const int MAX_M = 100000; const int INF = 1 << 30; /* typedef */ typedef long long ll; /* global variables */ int ls[MAX_N]; /* subroutines */ /* main */ int main() { int n, m; scanf("%d%d", &n, &m); for (int i = 0; i < n; i++) scanf("%d", ls + i); ll sum = 0; while (m--) { int f, b, w; scanf("%d%d%d", &f, &b, &w); int k = lower_bound(ls, ls + n, f) - ls; int c0 = (k > 0) ? f - ls[k - 1] : INF; int c1 = (k < n) ? ls[k] - f : INF; int c = min(c0, c1); sum += max(b, w - c); } printf("%lld\n", sum); return 0; }