#include #include using namespace std; #define ll long long #define ld long double const ll M = 1e9+7; int main() { ll n,m,ans=0,r=0;cin >> m >> n;set arr; for (ll i = 0; i < m; i++){ll a;cin >> a;arr.insert(a);} while(n--){ ll cor,a,b;cin >> cor >> a >> b; auto it=arr.lower_bound(cor); auto _it=it;_it--; if(it==arr.end())it--; if(it==arr.begin())_it++; if(*it==cor)ans+=b; else ans+=max({a,b-abs(cor-*_it),b-abs(*it-cor)}); }cout << ans; }