Problem p02647 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <cctype>    // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <cstdint> // int64_t, int*_t
#include <cstdio>  // printf
#include <cstdlib>
#include <deque> // deque
#include <iomanip>
#include <iostream>
#include <limits>
#include <map> // map
#include <numeric>
#include <queue> // queue, priority_queue
#include <set>   // set
#include <stack> // stack
#include <stdio.h>
#include <string>        // string, to_string, stoi
#include <tuple>         // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility>       // pair, make_pair
#include <vector>        // vector
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)

int main() {
  ll N, K;
  cin >> N >> K;
  bool m = true;

  vector<vector<ll>> A(100, vector<ll>(N + 1));
  vector<vector<ll>> kara(100, vector<ll>(N + 1));
  vector<vector<ll>> made(100, vector<ll>(N + 1));
  rep(i, N) { cin >> A.at(0).at(i); }
  if (N == 1) {
    cout << 1 << endl;
    return 0;
  }

  if (K >= 95) {
    K = 95;
  }
  ll ka = 0;
  while (ka <= K) {
    rep(i, N) {
      kara.at(ka).at(max(i - A.at(ka).at(i), ll(0)))++;
      made.at(ka).at(min(A.at(ka).at(i) + i, N - 1))++;
    }
    A.at(ka + 1).at(0) = kara.at(ka).at(0);
    for (ll i = 1; i < N; i++) {
      A.at(ka + 1).at(i) =
          A.at(ka + 1).at(i - 1) + kara.at(ka).at(i) - made.at(ka).at(i - 1);
    }

    ka++;
  }
  rep(i, N) { cout << A.at(K).at(i) << " "; }
}


Error: WA

Fixed submission:

#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <cctype>    // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <cstdint> // int64_t, int*_t
#include <cstdio>  // printf
#include <cstdlib>
#include <deque> // deque
#include <iomanip>
#include <iostream>
#include <limits>
#include <map> // map
#include <numeric>
#include <queue> // queue, priority_queue
#include <set>   // set
#include <stack> // stack
#include <stdio.h>
#include <string>        // string, to_string, stoi
#include <tuple>         // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility>       // pair, make_pair
#include <vector>        // vector
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)

int main() {
  ll N, K;
  cin >> N >> K;
  bool m = true;

  vector<vector<ll>> A(41, vector<ll>(N + 1));
  vector<vector<ll>> kara(41, vector<ll>(N + 1));
  vector<vector<ll>> made(41, vector<ll>(N + 1));
  rep(i, N) {
    cin >> A.at(0).at(i);
    if (A.at(0).at(i) != N)
      m = false;
  }
  if (N == 1) {
    cout << 1 << endl;
    return 0;
  }

  if (K > 40) {
    K = 40;
  }
  ll ka = 0;
  while (!m && ka <= K) {
    rep(i, N) {
      kara.at(ka).at(max(i - A.at(ka).at(i), ll(0)))++;
      made.at(ka).at(min(A.at(ka).at(i) + i, N - 1))++;
    }
    A.at(ka + 1).at(0) = kara.at(ka).at(0);
    for (ll i = 1; i < N; i++) {
      A.at(ka + 1).at(i) =
          A.at(ka + 1).at(i - 1) + kara.at(ka).at(i) - made.at(ka).at(i - 1);
    }

    ka++;
  }
  rep(i, N) { cout << A.at(K).at(i) << " "; }
}