Advertisement
SorahISA

[PCCA 2020 pG]

Feb 13th, 2020
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.72 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define int long long
  5.  
  6. #define fastIO() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
  7. #define X first
  8. #define Y second
  9.  
  10. int32_t main() {
  11.     fastIO();
  12.    
  13.     int n, k, ans = 0;
  14.     cin >> n >> k;
  15.    
  16.     vector<int> a(n);
  17.     vector<pair<int, int>> jump(n);
  18.     for (auto &x : a) cin >> x;
  19.    
  20.     for (int i = n-1; i >= 0; --i) {
  21.         if (i + a[i] >= n) {
  22.             jump[i].X = n;
  23.             jump[i].Y = 1;
  24.         }
  25.         else {
  26.             jump[i].X = jump[i + a[i]].X;
  27.             jump[i].Y = jump[i + a[i]].Y + 1;
  28.         }
  29.         ans += (jump[i].Y <= k and jump[i].X == n);
  30.     }
  31.    
  32.     cout << ans << "\n";
  33.    
  34.     return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement