#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]; vector po; int bin(int tar, int left, int right){ int l = left; int r = right; int mid; int ans = -1; while(l<=r){ mid = (l+r)/2; if(po[mid] tar){ r = mid-1; ans = po[mid]; } } return ans; } int bin2(int tar, int left, int right){ // cout << " tar" << left << " " << right << endl; int l = left; int r = right; int mid; int ans = -1; while(l<=r){ // cout << " "<< l <<" "<tar){ r = mid-1; }else if(po[mid] < tar){ l = mid+1; ans = po[mid]; } } // cout << " "<> n >> m; for(int i = 0; i < n; i++){ int a; cin >> a; po.pb(a); ar[a] = true; } sort(po.begin(), po.end()); // for(auto n : po) cout << n << " "; 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; int kanan = bin(f, 0, n-1); if(kanan!=-1) ma = min(ma,kanan-f); // cout << f << endl; // cout << " kan "<< kanan << endl; int kiri = bin2(f, 0, n-1); // cout << " kir "<> n; // while(n--){ solve(); // } }