#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N;
long long L;
if (!(cin >> N >> L)) return 0;
vector<long long> X(N);
for (int i = 0; i < N; ++i) cin >> X[i];
// compress positions: map pos -> count
map<long long,int> cntmap;
for (auto x : X) cntmap[x]++;
vector<long long> pos;
vector<int> cnts;
for (auto &p : cntmap) {
pos.push_back(p.first);
cnts.push_back(p.second);
}
int M = (int)pos.size();
auto simulate_order = [&](long long S, long long G, bool goLeftFirst)-> long long {
// build left/right indices relative to S
vector<int> left_idx, right_idx;
for (int i = 0; i < M; ++i) {
if (pos[i] <= S) left_idx.push_back(i);
else right_idx.push_back(i);
}
vector<int> visit; visit.reserve(M);
if (goLeftFirst) {
for (int i = (int)left_idx.size() - 1; i >= 0; --i) visit.push_back(left_idx[i]);
for (int i = 0; i < (int)right_idx.size(); ++i) visit.push_back(right_idx[i]);
} else {
for (int i = 0; i < (int)right_idx.size(); ++i) visit.push_back(right_idx[i]);
for (int i = (int)left_idx.size() - 1; i >= 0; --i) visit.push_back(left_idx[i]);
}
ll time = 0;
ll curPos = S;
ll carrying = 0;
vector<bool> picked(M, false);
// simulate visiting in this fixed order; pick only when we "visit" that position
for (int idx : visit) {
long long nextP = pos[idx];
long long d = llabs(curPos - nextP);
// movement cost: (carrying + 1) seconds per meter
time += d * (carrying + 1);
// arrive, pick all balls at nextP
carrying += cnts[idx];
time += cnts[idx]; // pick cost (1s per ball)
picked[idx] = true;
curPos = nextP;
}
// after collected all balls, move to G carrying all balls
long long dlast = llabs(curPos - G);
time += dlast * (carrying + 1);
return time;
};
int Q;
cin >> Q;
for (int qi = 0; qi < Q; ++qi) {
long long S, G, Tlim;
cin >> S >> G >> Tlim;
long long t1 = simulate_order(S, G, true);
long long t2 = simulate_order(S, G, false);
long long best = min(t1, t2);
if (best <= Tlim) cout << "Yes\n"; else cout << "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... |