#include #include #include #include #include #include using namespace atcoder; using namespace std; using ll = long long; using ull = unsigned long long; template using max_heap = priority_queue; template using min_heap = priority_queue, greater<>>; ll ll_min = numeric_limits::min(); ll ll_max = numeric_limits::max(); ll ALPHABET_N = 26; using mint = modint998244353; #define rep(i, n) for (ll i = (ll)0; i < (ll)n; i++) #define rep_(i, k, n) for (ll i = (ll)k; i < (ll)n; i++) #define all(a) a.begin(), a.end() int main() { ios::sync_with_stdio(false); cin.tie(0); ll n, s, t, k; cin >> n >> s >> t >> k; s--; t--; set> a_i; vector A(n); rep(i, n) { cin >> A[i]; a_i.insert({A[i], i}); } vector dist(n, ll_max); dist[s] = 0; queue q; q.push(s); a_i.erase({A[s], s}); while (!q.empty()) { ll v = q.front(); q.pop(); if (v == t) { cout << dist[v] << endl; return 0; } for (auto it = a_i.begin(); it != a_i.end();) { ll a = it->first; ll i = it->second; if (!(A[v] + a <= k)) { break; } dist[i] = dist[v] + 1; q.push(i); it = a_i.erase(it); } } cout << (dist[t] == ll_max ? -1 : dist[t]) << endl; return 0; }