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

// raja1999

// #pragma comment(linker, "/stack:200000000")
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2")

#include <algorithm>
#include <bits/stdc++.h>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <iomanip>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
// setbase - cout << setbase (16)a; cout << 100 << endl; Prints 64
// setfill -   cout << setfill ('x') << setw (5); cout << 77 <<endl;prints xxx77
// setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
// cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val

using namespace std;
using namespace __gnu_pbds;
#define f(i, a, b) for (i = a; i < b; i++)
#define rep(i, n) f(i, 0, n)
#define fd(i, a, b) for (i = a; i >= b; i--)
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define vl vector<ll>
#define ss second
#define ff first
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define sz(a) a.size()
#define inf (1000 * 1000 * 1000 + 5)
#define all(a) a.begin(), a.end()
#define tri pair<int, pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000 * 1000 * 1000 + 7)
#define pqueue priority_queue<int>
#define pdqueue priority_queue<int, vi, greater<int>>
// #define int ll

typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    ordered_set;

// std::ios::sync_with_stdio(false);
int arr[200005];
vi v;
int k;
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(NULL);
  int n = 100000, i, t, l, r, fl = 0, x;
  cin >> n >> k;
  rep(i, n) {
    cin >> x;
    v.pb(x);
  }
  t = k;
  while (t--) {
    fl = 0;
    rep(i, v.size()) {
      l = max(0, i - v[i]);
      r = min(n - 1, i + v[i]);
      arr[l]++;
      arr[r + 1]--;
    }
    rep(i, n) {
      arr[i] = i > 0 ? arr[i - 1] + arr[i] : arr[i];
      v[i] = arr[i];
      if (v[i] != n) {
        fl = 1;
      }
    }
    rep(i, n) { arr[i] = 0; }
    if (fl == 0) {
      break;
    }
  }
  rep(i, n) { cout << v[i] << " "; }
  cout << endl;
  return 0;
}

Error: WA

Fixed submission:

// raja1999

// #pragma comment(linker, "/stack:200000000")
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2")

#include <algorithm>
#include <bits/stdc++.h>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <iomanip>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
// setbase - cout << setbase (16)a; cout << 100 << endl; Prints 64
// setfill -   cout << setfill ('x') << setw (5); cout << 77 <<endl;prints xxx77
// setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
// cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val

using namespace std;
using namespace __gnu_pbds;
#define f(i, a, b) for (i = a; i < b; i++)
#define rep(i, n) f(i, 0, n)
#define fd(i, a, b) for (i = a; i >= b; i--)
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define vl vector<ll>
#define ss second
#define ff first
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define sz(a) a.size()
#define inf (1000 * 1000 * 1000 + 5)
#define all(a) a.begin(), a.end()
#define tri pair<int, pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000 * 1000 * 1000 + 7)
#define pqueue priority_queue<int>
#define pdqueue priority_queue<int, vi, greater<int>>
// #define int ll

typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    ordered_set;

// std::ios::sync_with_stdio(false);
int arr[100005];
vi v;
int k;
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(NULL);
  int n = 100000, i, t, l, r, fl = 0, x;
  cin >> n >> k;
  rep(i, n) {
    cin >> x;
    v.pb(x);
  }
  t = k;
  while (t--) {
    fl = 0;
    rep(i, v.size()) {
      l = max(0, i - v[i]);
      r = min(n - 1, i + v[i]);
      arr[l]++;
      arr[r + 1]--;
    }
    rep(i, n) {
      arr[i] = i > 0 ? arr[i - 1] + arr[i] : arr[i];
      v[i] = arr[i];
      if (v[i] != n) {
        fl = 1;
      }
    }
    rep(i, n) { arr[i] = 0; }
    if (fl == 0) {
      break;
    }
  }
  rep(i, n) { cout << v[i] << " "; }
  cout << endl;
  return 0;
}