#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define int long long
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<bool> vb;
typedef tree<pii,null_type,less<pii>,rb_tree_tag,
tree_order_statistics_node_update> oset;
#define fi first
#define se second
#define pb push_back
#define pf push_front
#define mid (l+r)/2
#define all(x) x.begin(),x.end()
#define FOR(i,a) for(int i=0;i<(a);i++)
#define FORE(i,a,b) for(int i=(a);i<(b);i++)
#define cont(x) for(auto el:x) cout<<el<<' ';cout<<endl;
#define contp(x) for(auto el:x) cout<<el.fi<<'-'<<el.se<<' ';cout<<endl;
#define sp <<" "<<
#define DEBUG(x) cout<<(#x) sp x<<endl
#define carp(a,b) (((a%MOD)*(b%MOD))%MOD)
#define topla(a,b) (((a%MOD)+(b%MOD))%MOD)
const int INF=1e18;
const int MAXN=2e5+5;
const int MOD=998244353;
int n,l;
vi x;
int mn;
void solve(int bas,int son){
    mn=0;
    int pos=bas;
    int top=0;
    
    if(bas<=son){
        int git=1;
        //önce 1-bas olanları al
        if(x[1]<bas){
            mn+=pos-x[1];
            pos=x[1];
            top++;
            mn++;
            git++;
        }
        //DEBUG(mn);
        FORE(i,git,n+1){
            if(x[i]>=son) break;
            //tüm topları al
            mn+=(top+1)*(x[i]-pos);
            pos=x[i];
            top++;
            mn++;
            //DEBUG(mn);
        }
        mn+=(top+1)*(son-pos);
        pos=son;
        //top=0;
        git=n;
        //DEBUG(mn);
        if(x[n]>son){
            mn+=(top+1)*x[n]-son;
            pos=x[n];
            top++;
            mn++;
            git--;
            //DEBUG(mn);
        }
        for(int i=git;i>0;i--){
            if(x[i]<son) break;
            mn+=(top+1)*(pos-x[i]);
            pos=x[i];
            top++;
            mn++;
            //DEBUG(mn);
        }
        mn+=(top+1)*(pos-son);
        pos=son;
        //top=0;
        //DEBUG(mn);
    }
    else{
        //önce bas-n olanları al
        int git=n;
        if(x[n]>bas){
            mn+=x[n]-bas;
            pos=x[n];
            top++;
            mn++;
            git--;
        }
        for(int i=git;i>0;i--){
            if(x[i]<=son) break;
            mn+=(top+1)*(pos-x[i]);
            pos=x[i];
            top++;
            mn++;
        }
        mn+=(top+1)*(pos-son);
        pos=son;
        //top=0;
        git=1;
        if(x[1]<son){
            mn+=(top+1)*(pos-x[1]);
            pos=x[1];
            top++;
            mn++;
            git++;
        }
        FORE(i,git,n+1){
            if(x[i]>son) break;
            //tüm topları al
            mn+=(top+1)*(x[i]-pos);
            pos=x[i];
            top++;
            mn++;
        }
        mn+=(top+1)*(son-pos);
        pos=son;
        top=0;
    }
}
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>l;
    x.resize(n+1);
    FORE(i,1,n+1) cin>>x[i];
    sort(all(x));
    int q;
    cin>>q;
    while(q--){
        int bas,son,t;
        cin>>bas>>son>>t;
        solve(bas,son);
        //DEBUG(mn);
        if(mn<=t) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
}
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |