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

//****** @mdazmat9 **********
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
#define UB upper_bound
#define LB lower_bound
#define BS binary_search
#define EB emplace_back
#define PB push_back
#define endl "\\n"
#define MOD 1000000007
#define MOD2 998244353
#define F first
#define S second
#define ALL(a) (a).begin(), (a).end()
typedef pair<int, int> pr;
typedef vector<int> VI;
typedef vector<pr> VP;
typedef vector<string> VS;
typedef vector<vector<int>> VV;
#define IOS                                                                    \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
#define trace1(x) cout << #x << ": " << x << endl
#define trace2(x, y) cout << #x << ": " << x << " | " << #y << ": " << y << endl
#define trace3(x, y, z)                                                        \\
  cout << #x << ":" << x << " | " << #y << ": " << y << " | " << #z << ": "    \\
       << z << endl
#define trace4(a, b, c, d)                                                     \\
  cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": "   \\
       << c << " | " << #d << ": " << d << endl
#define trace5(a, b, c, d, e)                                                  \\
  cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": "   \\
       << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl
#define trace6(a, b, c, d, e, f)                                               \\
  cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": "   \\
       << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | "   \\
       << #f << ": " << f << endl
#define trace(v)                                                               \\
  for (auto it = v.begin(); it != v.end(); it++)                               \\
    cout << *it << " ";                                                        \\
  cout << endl;
const int inf = 1e17;
const int MAXN = 200001;
int fast_pow(int x, int y, int p);

void update(vector<int> &D, int l, int r, int x) {
  D[l] += x;
  D[r + 1] -= x;
}

int getOriginal(vector<int> &A, vector<int> &D) {
  int mn = INT_MAX;
  int n = A.size();
  for (int i = 0; i < n; i++) {
    if (i == 0)
      A[i] = D[i];
    else
      A[i] = D[i] + A[i - 1];
    mn = min(mn, A[i]);
  }
  return mn;
}

void solve() {
  int n, k;
  cin >> n >> k;
  VI v;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    v.EB(x);
  }
  while (k > 0) {
    VI D(n + 1, 0);
    for (int i = 0; i < n; i++) {
      int left = max(0ll, i - v[i]);
      int right = min(n - 1, i + v[i]);
      update(D, left, right, 1);
    }
    int mn = getOriginal(v, D);
    if (mn == n)
      break;
    k--;
  }
  for (int i = 0; i < n; i++) {
    cout << v[i] << " ";
  }
}

int32_t main() {

  IOS;
  int test = 1;
  // cin>>test;
  for (int i = 1; i <= test; i++) {
    // cout<<"Case #"<<i<<": ";
    solve();
  }
  return 0;
}
int fast_pow(int x, int y, int p) {
  int res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1)
      res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}

Error: WA

Fixed submission:

//****** @mdazmat9 **********
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
#define UB upper_bound
#define LB lower_bound
#define BS binary_search
#define EB emplace_back
#define PB push_back
#define endl "\\n"
#define MOD 1000000007
#define MOD2 998244353
#define F first
#define S second
#define ALL(a) (a).begin(), (a).end()
typedef pair<int, int> pr;
typedef vector<int> VI;
typedef vector<pr> VP;
typedef vector<string> VS;
typedef vector<vector<int>> VV;
#define IOS                                                                    \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
#define trace1(x) cout << #x << ": " << x << endl
#define trace2(x, y) cout << #x << ": " << x << " | " << #y << ": " << y << endl
#define trace3(x, y, z)                                                        \\
  cout << #x << ":" << x << " | " << #y << ": " << y << " | " << #z << ": "    \\
       << z << endl
#define trace4(a, b, c, d)                                                     \\
  cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": "   \\
       << c << " | " << #d << ": " << d << endl
#define trace5(a, b, c, d, e)                                                  \\
  cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": "   \\
       << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl
#define trace6(a, b, c, d, e, f)                                               \\
  cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": "   \\
       << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | "   \\
       << #f << ": " << f << endl
#define trace(v)                                                               \\
  for (auto it = v.begin(); it != v.end(); it++)                               \\
    cout << *it << " ";                                                        \\
  cout << endl;
const int inf = 1e17;
const int MAXN = 200001;
int fast_pow(int x, int y, int p);

void update(vector<int> &D, int l, int r, int x) {
  D[l] += x;
  D[r + 1] -= x;
}

int getOriginal(vector<int> &A, vector<int> &D) {
  int mn = INT_MAX;
  for (int i = 0; i < A.size(); i++) {
    if (i == 0)
      A[i] = D[i];
    else
      A[i] = D[i] + A[i - 1];
    mn = min(mn, A[i]);
  }
  return mn;
}

void solve() {
  int n, k;
  cin >> n >> k;
  VI v;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    v.EB(x);
  }
  while (k > 0) {
    VI D(n + 1, 0);
    for (int i = 0; i < n; i++) {
      int left = max(0ll, i - v[i]);
      int right = min(n, i + v[i]);
      update(D, left, right, 1);
    }
    int mn = getOriginal(v, D);
    if (mn == n)
      break;
    k--;
  }
  for (int i = 0; i < n; i++) {
    cout << v[i] << " ";
  }
}

int32_t main() {

  IOS;
  int test = 1;
  // cin>>test;
  for (int i = 1; i <= test; i++) {
    // cout<<"Case #"<<i<<": ";
    solve();
  }
  return 0;
}
int fast_pow(int x, int y, int p) {
  int res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1)
      res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}