Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define int long long
- #define fastIO() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
- #define X first
- #define Y second
- int32_t main() {
- fastIO();
- int n, k, ans = 0;
- cin >> n >> k;
- vector<int> a(n);
- vector<pair<int, int>> jump(n);
- for (auto &x : a) cin >> x;
- for (int i = n-1; i >= 0; --i) {
- if (i + a[i] >= n) {
- jump[i].X = n;
- jump[i].Y = 1;
- }
- else {
- jump[i].X = jump[i + a[i]].X;
- jump[i].Y = jump[i + a[i]].Y + 1;
- }
- ans += (jump[i].Y <= k and jump[i].X == n);
- }
- cout << ans << "\n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement