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

#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define endl "\\n"
#define sz(x) ((ll)(x).size())
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define prt(x) cout << (x)
#define prtl(x) cout << (x) << endl
#define rep(i, a, b) for (ll i = a; i < b; i++)
#define rrep(i, a, b) for (ll i = a; i > b; i--)
#define mp(a, b) make_pair(a, b)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;
using vi = vector<int>;
using vll = vector<long long int>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vc = vector<char>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<long long int>>;
using vvc = vector<vector<char>>;
using ll = long long int;
using P = pair<long long int, long long int>;
using Map = map<long long int, long long int>;
ll INF = 1LL << 60;
ll M = 1000000007;

int main() {
  ll N, K;
  cin >> N >> K;
  vll a(N);
  rep(i, 0, N) { cin >> a[i]; }
  bool t = true;
  ll c = 0;
  while (t && c < K) {
    vll imos(N + 1, 0);
    rep(i, 0, N) {
      ll l = i - a[i];
      if (l < 0) {
        l = 0;
      }
      ll r = i + a[i] + 1;
      if (N < r) {
        r = N;
      }
      imos[l]++;
      imos[r]--;
    }
    ll sm = 0;
    bool f = true;
    rep(i, 0, N) {
      sm += imos[i];
      a[i] = min(sm, N);
      if (a[i] != N) {
        f = false;
      }
    }
    if (f) {
      t = false;
    }
    c++;
  }
  if (!t) {
    rep(i, 0, N) {
      prt(N);
      prt(" ");
    }
  } else {
    rep(i, 0, N) {
      prt(a[i]);
      prt(" ");
    }
  }
}

Error: WA

Fixed submission:

#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define endl "\\n"
#define sz(x) ((ll)(x).size())
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define prt(x) cout << (x)
#define prtl(x) cout << (x) << endl
#define rep(i, a, b) for (ll i = a; i < b; i++)
#define rrep(i, a, b) for (ll i = a; i > b; i--)
#define mp(a, b) make_pair(a, b)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;
using vi = vector<int>;
using vll = vector<long long int>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vc = vector<char>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<long long int>>;
using vvc = vector<vector<char>>;
using ll = long long int;
using P = pair<long long int, long long int>;
using Map = map<long long int, long long int>;
ll INF = 1LL << 60;
ll M = 1000000007;

int main() {
  ll N, K;
  cin >> N >> K;
  vll a(N);
  rep(i, 0, N) { cin >> a[i]; }
  bool t = true;
  ll c = 0;
  while (t && c < K) {
    vll imos(N, 0);
    rep(i, 0, N) {
      ll l = i - a[i];
      if (l < 0) {
        l = 0;
      }
      ll r = i + a[i] + 1;
      if (N < r) {
        r = N;
      }
      imos[l]++;
      imos[r]--;
    }
    ll sum = 0;
    bool f = true;
    rep(i, 0, N) {
      sum += imos[i];
      a[i] = min(sum, N);
      if (a[i] != N) {
        f = false;
      }
    }
    if (f) {
      t = false;
    }
    c++;
  }
  if (!t) {
    rep(i, 0, N) {
      prt(N);
      prt(" ");
    }
  } else {
    rep(i, 0, N) {
      prt(a[i]);
      prt(" ");
    }
  }
}