#include <bits/stdc++.h>
using namespace std;
#define FOR(i, l, r) for(int i = (l); i < (r); ++i)
#define ROF(i, r, l) for(int i = (r) - 1; i >= (l); --i)
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define all(v) begin(v), end(v)
#define rall(v) rbegin(v), rend(v)
#define sz(v) (int)v.size()
#define pb push_back
#define eb emplace_back
#define compact(v) v.erase(unique(all(v)), end(v))
#define dbg(x) "[" #x " = " << (x) << "]"
template<typename T>
bool minimize(T& a, const T& b){
if(a > b) return a = b, true;
return false;
}
template<typename T>
bool maximize(T& a, const T& b){
if(a < b) return a = b, true;
return false;
}
using ll = long long;
using db = double;
using ld = long double;
using ull = unsigned long long;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using pd = pair<db, db>;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using vc = vector<char>;
using vd = vector<db>;
using vpi = vector<pi>;
using vpl = vector<pl>;
void setIO(){
ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef LOCAL
freopen("task.inp", "r", stdin);
freopen("task.ans", "w", stdout);
#endif // LOCAL
}
const int MAX = 5e5 + 5;
int N, M, L, X[MAX];
int main(){
setIO();
cin >> N >> L;
FOR(i, 0, N){
cin >> X[i];
}
int Q;
cin >> Q;
while(Q--){
int S, G, T; cin >> S >> G >> T;
vi perm(N);
iota(all(perm), 0);
ll best = 1e18;
do{
ll cur = abs(S - X[perm[0]]) + 1LL * (N+1) * abs(G - X[perm[N-1]]);
FOR(i, 1, N){
cur += 1LL * abs(X[perm[i-1]] - X[perm[i]]) * (i+1);
}
cur += N;
minimize(best, cur);
} while(next_permutation(all(perm)));
// cout << dbg(best) << '\n';
cout << (best <= T ? "Yes\n" : "No\n");
}
return 0;
}
# | 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... |