#include using namespace std; #define int long long #define ll long long #define pii pair #define pb push_back #define mp make_pair #define dbg puts("dbg"); #define outp(x) cout << #x << " = " << (x) << endl #define all(x) (x).begin(), (x).end() #define test int t; cin >> t; while(t--){solve();} #define MOD 998244353 int fpb(int a,int b){if(b == 0){return a;}return fpb(b, a%b);} int kpk(int a,int b){return (a*b)/fpb(a, b);} int n, m, l[100002]; map ada; struct fish{ int koordinat, kena, gakena; }; fish ikan[100002]; void solve(){ cin >> n >> m; for(int i=1; i<=n; i++){ cin >> l[i]; ada[l[i]] = 1; } int cnt = 0, tot = 0; for(int i=1; i<=m; i++){ cin >> ikan[i].koordinat >> ikan[i].kena >> ikan[i].gakena; if(ada[ikan[i].koordinat]){ tot += ikan[i].gakena; } else { int indeksUB = upper_bound(l+1, l+n+1, ikan[i].koordinat) - l; int majuOperasi = l[indeksUB] - ikan[i].koordinat; int mundurOperasi = ikan[i].koordinat - l[indeksUB-1]; int stayPosisiOperasi = 0; int majuMagis = ikan[i].gakena; int mundurMagis = ikan[i].gakena; int stayPosisiMagis = ikan[i].kena; if(indeksUB == n+1){ majuOperasi = 2e18; } else if(indeksUB == 1){ mundurOperasi = 2e18; } int finalMaju = majuMagis - majuOperasi, finalMundur = mundurMagis - mundurOperasi; int finalStay = stayPosisiMagis - stayPosisiOperasi; int maxi = max(finalMaju, max(finalStay, finalMundur)); tot += maxi; } } cout << tot << endl; } int32_t main() { ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); solve(); return 0; }