#include using namespace std; #define int long long #define ll long long #pragma GCC optimize ("O3") #pragma GCC optimize ("unroll-loops") #define fi first #define se second const int MOD = 1e9+7; #define pin pair #define lup(i,x) for(int i=0; i #define nitro ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define din(x) int x;cin>>x; #define endl '\n' #define cout std::cout const int maxn = 1e9+5; bool ar[maxn]; int bin(){ } void solve(){ int n, m; cin >> n >> m; for(int i = 0; i < n; i++){ int a; cin >> a; ar[a] = true; } int sum = 0; for(int i = 0; i < m; i ++ ){ int f, b, w; cin >> f >> b >> w; if(ar[f]==true){ sum += w; }else{ int ma = 1e11; for(int j = f+1; j < maxn; j++){ if(ar[j] == true) {ma = min(ma,(j-f)); break;}; } for(int j = f-1; j>=0; j--){ if(ar[j] == true) { ma = min(ma,(f-j)); } } if(ma==1e11){ sum+=b; }else{ if(b < w-ma){ sum += w-ma; }else{ sum += b; } } } } cout << sum << endl; } signed main(){ nitro // int n; // cin >> n; // while(n--){ solve(); // } }