prithivMLmods/Coder-Stat huggingface dataset:
Problem p02646 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
#define F first
#define S second
#define migmig                                                                 \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define ll long long
#define ld long double
#define pii pair<int, int>
#define bug(x) cout << "passed " << x << endl;
#define ashar(x, y, z)                                                         \
  cout << setprecision(x) << fixed << y;                                       \
  if (z == 1)                                                                  \
    cout << "\n";
#define ppi pair<pair<int, int>, int>
long long const inf = 3e18, linf = 2e9, mod = 1e9 + 7, inf2 = 1e12;
int const mxn = 5e5 + 10;

ll poww(ll a, ll b, ll md) {
  return (!b ? 1
             : (b & 1 ? a * poww(a * a % md, b / 2, md) % md
                      : poww(a * a % md, b / 2, md) % md));
}

int main() {
  int a, b, v, w, t;
  ;
  cin >> a >> v >> b >> w >> t;
  long long dis = abs(a - b);
  long long s = (v - w);
  if (dis == 0)
    cout << "YES";
  else if (s >= 0 and ((s == 0 and dis == 0) or dis / s + (dis % s > 1) <= t))
    cout << "YES";
  else
    cout << "NO";
}


Fixed submission:
#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
#define F first
#define S second
#define migmig                                                                 \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define ll long long
#define ld long double
#define pii pair<int, int>
#define bug(x) cout << "passed " << x << endl;
#define ashar(x, y, z)                                                         \
  cout << setprecision(x) << fixed << y;                                       \
  if (z == 1)                                                                  \
    cout << "\n";
#define ppi pair<pair<int, int>, int>
long long const inf = 3e18, linf = 2e9, mod = 1e9 + 7, inf2 = 1e12;
int const mxn = 5e5 + 10;

ll poww(ll a, ll b, ll md) {
  return (!b ? 1
             : (b & 1 ? a * poww(a * a % md, b / 2, md) % md
                      : poww(a * a % md, b / 2, md) % md));
}

int main() {
  int a, b, v, w, t;
  ;
  cin >> a >> v >> b >> w >> t;
  long long dis = abs(a - b);
  long long s = (v - w);
  if (dis == 0)
    cout << "YES";
  else if (s <= 0)
    cout << "NO";
  else if (dis / s + (dis % s > 0) <= t)
    cout << "YES";
  else
    cout << "NO";
}
Problem p02646 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#include <iostream>
#include <math.h>
using namespace std;
typedef long long ll;

int main(void) {
  ll a, b, v, w, t;
  cin >> a >> v >> b >> w >> t;

  cout << (abs(a - b) / (v - w) <= t ? "YES" : "NO") << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#include <iostream>
#include <math.h>
using namespace std;
typedef long long ll;

int main(void) {
  ll a, b, v, w, t;
  cin >> a >> v >> b >> w >> t;

  cout << (abs(a - b) <= (v - w) * t ? "YES" : "NO") << endl;
  return 0;
}
Problem p02646 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  int A, V, B, W, T = 0;
  cin >> A >> V >> B >> W >> T;
  int X = B - A;
  if (B > A && V >= W && (B - A) / (V - W) <= T) {
    cout << "YES" << endl;
  } else if (X == 0) {
    cout << "YES" << endl;
  } else if (B > A && W >= V && (B - A) / (V - W) <= T) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;

int main() {
  long long a, v, b, w, p;
  cin >> a >> v >> b >> w >> p;
  long long wdnmd = abs(b - a);
  long long xswl = (v - w) * p;
  if (wdnmd <= xswl) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}
Problem p02646 (C++)

Buggy submission (status: Runtime Error):
/*
    *****
    @Author: Harith Insider
    *****
*/
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define ff first
#define ss second
#define fastio                                                                 \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0);
using namespace std;
void solve() {
  ll x1, x2, t1, t2, t;
  cin >> x1 >> t1 >> x2 >> t2 >> t;
  ll v = abs(x1 - x2) / abs(t2 - t1);
  if (v > 0 and v <= t)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}
int main() {
  fastio;
  solve();
}

Fixed submission:
/*
    *****
    @Author: Harith Insider
    *****
*/
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define ff first
#define ss second
#define fastio                                                                 \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0);
using namespace std;
void solve() {
  ll x1, x2, t1, t2, t;
  cin >> x1 >> t1 >> x2 >> t2 >> t;
  ll a = abs(x1 - x2);
  ll b = (t1 - t2) * t;
  if (a <= b)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}
int main() {
  fastio;
  solve();
}
Problem p02646 (C++)

Buggy submission (status: Runtime Error):
/*
 * author :Sadik Hassan
 *
 */
#include "bits/stdc++.h"
using namespace std;
#define ll long long
#define nl "\n"
#define pb push_back
#define fi first
#define se second
#define PI (acos(-1.0))
#define _SAD()                                                                 \
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0),                            \
      cout << fixed << setprecision(20);
#define rep(i, n) for (int i = 0; i < n; i++)
#define SZ(s) s.size()
#define SRT(x, y) sort(x, x + y)
#define REV(a, b) reverse(a, a + b)
#define VSRT(x) sort(x.begin(), x.end())
#define VREV(x) reverse(x.begin(), x.end())
#define w(t)                                                                   \
  int t;                                                                       \
  cin >> t;                                                                    \
  while (t--)
#define TSFL(s) transform(s.begin(), s.end(), s.begin(), ::toupper);
#define TSFH(s) transform(s.begin(), s.end(), s.begin(), ::tolower);
typedef vector<int> vi;
typedef vector<ll> vii;
typedef set<int> si;
typedef set<ll> sii;
/*---------------------------------------------------------------------*/

const int N = 2e5 + 10;
const int INF = (int)1e9 + 5;

int main() {
  _SAD()
  int a, b, m, n, t;
  cin >> a >> m >> b >> n >> t;
  a = abs(a - b);
  m -= n;
  if ((a + m - 1) / m <= t && m > 0)
    cout << "YES";
  else
    cout << "NO";
  return 0;
}


Fixed submission:
/*
 * author :Sadik Hassan
 *
 */
#include "bits/stdc++.h"
using namespace std;
#define ll long long
#define nl "\n"
#define pb push_back
#define fi first
#define se second
#define PI (acos(-1.0))
#define _SAD()                                                                 \
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0),                            \
      cout << fixed << setprecision(20);
#define rep(i, n) for (int i = 0; i < n; i++)
#define SZ(s) s.size()
#define SRT(x, y) sort(x, x + y)
#define REV(a, b) reverse(a, a + b)
#define VSRT(x) sort(x.begin(), x.end())
#define VREV(x) reverse(x.begin(), x.end())
#define w(t)                                                                   \
  int t;                                                                       \
  cin >> t;                                                                    \
  while (t--)
#define TSFL(s) transform(s.begin(), s.end(), s.begin(), ::toupper);
#define TSFH(s) transform(s.begin(), s.end(), s.begin(), ::tolower);
typedef vector<int> vi;
typedef vector<ll> vii;
typedef set<int> si;
typedef set<ll> sii;
/*---------------------------------------------------------------------*/

const int N = 2e5 + 10;
const int INF = (int)1e9 + 5;

int main() {
  _SAD()
  int a, b, m, n, t;
  cin >> a >> m >> b >> n >> t;
  a = abs(a - b);
  m -= n;
  if (m <= 0)
    cout << "NO";
  else if ((a + m - 1) / m <= t)
    cout << "YES";
  else
    cout << "NO";
  return 0;
}
Problem p02646 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

bool solve() {
  int a, v, b, w, t;
  cin >> a >> v >> b >> w >> t;
  int dist = abs(b - a);
  int dv = (v - w);
  if (dv < 0)
    return false;
  int steps = dist / dv;
  if (dist % dv)
    ++steps;
  if (steps <= t)
    return true;
  return false;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(10);
  cout << fixed;

  if (solve()) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;

bool solve() {
  int a, v, b, w, t;
  cin >> a >> v >> b >> w >> t;
  int dist = abs(b - a);
  int dv = (v - w);
  if (dv <= 0)
    return false;
  int steps = dist / dv;
  if (dist % dv)
    ++steps;
  if (steps <= t)
    return true;
  return false;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(10);
  cout << fixed;

  if (solve()) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }

  return 0;
}
Problem p02646 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
#define pri(str) cout << str << endl
using ll = long long;
using P = pair<int, int>;

const ll MX = 1e18;
const long double PI = acos(-1);

int main() {
  ll a, b, v, w, t;
  cin >> a >> v >> b >> w >> t;
  ll ans = (a - b) / (w - v);
  if (w - v != 0 && ans <= t && ans > 0 && (a - b) % (w - v) == 0)
    pri("YES");
  else
    pri("NO");
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
#define pri(str) cout << str << endl
using ll = long long;
using P = pair<int, int>;

const ll MX = 1e18;
const long double PI = acos(-1);

int main() {
  ll a, b, v, w, t;
  cin >> a >> v >> b >> w >> t;
  if (abs(a - b) <= t * (v - w))
    pri("YES");
  else
    pri("NO");
  return 0;
}
Problem p02646 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

typedef long long int ll;
int main() {
  ll a, b;
  ll v, w;
  cin >> a >> v;
  cin >> b >> w;
  ll t;
  cin >> t;
  puts((abs(a - b) / (v - w)) <= t ? "YES" : "NO");
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;

typedef long long int ll;
int main() {
  ll a, b;
  ll v, w;
  cin >> a >> v;
  cin >> b >> w;
  ll t;
  cin >> t;
  ll t1 = abs(a - b);
  ll t2 = (v - w) * t;
  if (t1 <= t2) {
    cout << "YES";
  } else {
    cout << "NO";
  }
  return 0;
}
Problem p02646 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e7 + 5;
const int maxm = 5e5 + 5;
const ll inf = 2147483647;

int main() {
  ll a, v, b, w, t;
  int f = 0;
  cin >> a >> v >> b >> w >> t;
  ll d = abs(a - b);
  ll k = abs(v - w);
  if (d / k <= t) {
    cout << "YES";
    return 0;
  }
  cout << "NO";
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e7 + 5;
const int maxm = 5e5 + 5;
const ll inf = 2147483647;

int main() {
  ll a, v, b, w, t;
  int f = 0;
  cin >> a >> v >> b >> w >> t;

  if (abs(a - b) <= (v - w) * t) {
    cout << "YES";
    return 0;
  }
  cout << "NO";
  return 0;
}
Problem p02646 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define fi first
#define se second
#define pb push_back
#define forn(i, n) for (int i = 0; i < (n); i++)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define forr(i, n) for (int i = n; i >= 0; i--)
#define all(x) x.begin(), x.end()
const int MAXN = 1e5 + 5;

void fio() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}

int main() {
  fio();
  vector<pair<LL, LL>> v(2);
  forn(i, 2) cin >> v[i].fi >> v[i].se;
  LL t;
  cin >> t;
  sort(all(v));
  LL vi = -v[1].se + v[0].se;
  if (v[1].fi == v[0].fi) {
    cout << "YES" << endl;
    return 0;
  }
  if (vi < 0 && v[1].fi != v[0].fi) {
    cout << "NO" << endl;
    return 0;
  }
  if (t >= ((v[1].fi - v[0].fi) / (vi)) && vi >= ((v[1].fi - v[0].fi) / (t))) {
    cout << "YES" << endl;
  } else
    cout << "NO" << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define fi first
#define se second
#define pb push_back
#define forn(i, n) for (int i = 0; i < (n); i++)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define forr(i, n) for (int i = n; i >= 0; i--)
#define all(x) x.begin(), x.end()
const int MAXN = 1e5 + 5;

void fio() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}

int main() {
  fio();
  vector<pair<LL, LL>> v(2);
  forn(i, 2) cin >> v[i].fi >> v[i].se;
  LL t;
  cin >> t;
  LL vi = v[0].se - v[1].se;
  if (vi * t >= (abs(v[0].fi - v[1].fi))) {
    cout << "YES" << endl;
  } else
    cout << "NO" << endl;
  return 0;
}
Problem p02646 (C++)

Buggy submission (status: Runtime Error):
#pragma GCC optimize("-Ofast", "-funroll-all-loops")
#include <bits/stdc++.h>
// #define int long long
using namespace std;
int a, b, v, w, t;
signed main() {
  cin >> a >> v >> b >> w >> t;
  if (w >= v)
    puts("NO");
  else if (abs(a - b) <= 1LL * t * (v - w))
    return puts("YES");
  else
    puts("NO");
  return 0;
}


Fixed submission:
#pragma GCC optimize("-Ofast", "-funroll-all-loops")
#include <bits/stdc++.h>
// #define int long long
using namespace std;
int a, b, v, w, t;
signed main() {
  cin >> a >> v >> b >> w >> t;
  if (w >= v)
    puts("NO");
  else if (abs(a - b) <= 1LL * t * (v - w))
    puts("YES");
  else
    puts("NO");
  return 0;
}
Problem p02646 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MOD = 1000000007;

int main() {
  ll a, v, b, w, t;
  cin >> a >> v >> b >> w >> t;
  ll T = (b - a + v - w - 1) / (v - w);
  if (T > 0 && T <= t)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MOD = 1000000007;

int main() {
  ll a, v, b, w, t;
  cin >> a >> v >> b >> w >> t;
  ll dis;
  if (a < b)
    dis = b - a + (w - v) * t;
  else
    dis = a - b + (w - v) * t;
  if (dis <= 0)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}
Problem p02646 (C++)

Buggy submission (status: Runtime Error):

/**
 *    Coded by : lucky_21
 *               --------Lokesh Singh
 **/

#include <bits/stdc++.h>
using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <class T>
using oset =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define F first
#define S second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define pii pair<int, int>
#define all(x) x.begin(), x.end()
#define fix fixed << setprecision(10)
#define rep(i, a, b) for (int i = int(a); i <= int(b); i++)
#define repb(i, b, a) for (int i = int(b); i >= int(a); i--)
#define FastIO ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)

typedef double db;
typedef long long ll;

const int N = 2e5 + 5;
const int mod = 1e9 + 7;

signed main() {
  FastIO;
  ll a, b, c, d, t;
  cin >> a >> b >> c >> d >> t;
  if ((c - a) <= (b - d) * t and (c - a) % (b - d) == 0)
    return cout << "YES", 0;
  cout << "NO";
  return 0;
}


Fixed submission:

/**
 *    Coded by : lucky_21
 *               --------Lokesh Singh
 **/

#include <bits/stdc++.h>
using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <class T>
using oset =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define F first
#define S second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define pii pair<int, int>
#define all(x) x.begin(), x.end()
#define fix fixed << setprecision(10)
#define rep(i, a, b) for (int i = int(a); i <= int(b); i++)
#define repb(i, b, a) for (int i = int(b); i >= int(a); i--)
#define FastIO ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)

typedef double db;
typedef long long ll;

const int N = 2e5 + 5;
const int mod = 1e9 + 7;

signed main() {
  FastIO;
  ll a, b, c, d, t;
  cin >> a >> b >> c >> d >> t;
  if (a < c) {
    return cout << ((c - a) <= (b - d) * t ? "YES" : "NO"), 0;
  }
  cout << ((a - c) <= (b - d) * t ? "YES" : "NO");
  return 0;
}
Problem p02646 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long a, v, b, w, t;
  cin >> a >> v >> b >> w >> t;
  long long x = a - b;
  if (x < 0) {
    x *= -1;
  }
  if (((x / (v - w)) <= t) && (x / (v - w)) > 0)
    cout << "YES";
  else {
    cout << "NO";
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long a, v, b, w, t;
  cin >> a >> v >> b >> w >> t;
  long long x = a - b;
  if (x < 0) {
    x *= -1;
  }
  if ((x <= t * (v - w)) && (v - w) > 0)
    cout << "YES";
  else {
    cout << "NO";
  }
}
Problem p02646 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {

  ll a, v;
  cin >> a >> v;
  ll b, w;
  cin >> b >> w;
  ll t;
  cin >> t;

  if (abs(a - b) / (v - w) <= t)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {

  ll a, v;
  cin >> a >> v;
  ll b, w;
  cin >> b >> w;
  ll t;
  cin >> t;

  if (abs(a - b) <= (v - w) * t)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}
Problem p02646 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#define inf 0x3f3f3f3f
const int maxn = 3000050;
using namespace std;
typedef long long ll;
int main() {
  ll a, b, v, w, t;
  cin >> a >> v >> b >> w >> t;
  if (a == b) {
    cout << "Yes";
    return 0;
  }
  if ((v <= w && a < b) || abs(a - b) % abs(v - w)) {
    cout << "No";
  } else {
    if (t >= abs(a - b) / abs(v - w)) {
      cout << "Yes";
    } else
      cout << "No";
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#define inf 0x3f3f3f3f
const int maxn = 3000050;
using namespace std;
typedef long long ll;
int main() {
  ll A, V;
  cin >> A >> V;
  ll B, W;
  cin >> B >> W;
  ll T;
  cin >> T;
  ll D = abs(A - B);
  ll D2 = (V - W) * T;
  puts(D <= D2 ? "YES" : "NO");
}
Problem p02646 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
using namespace std;
int main() {
  int A, V, B, W, T;
  scanf("%lld%lld%lld%lld%lld", &A, &V, &B, &W, &T);
  if (abs(A - B) > (V - W) * T) {
    printf("NO\n");
  } else
    printf("YES\n");
}

Fixed submission:
#include <algorithm>
#include <cstdio>
using namespace std;
int main() {
  long long A, V, B, W, T;
  scanf("%lld%lld%lld%lld%lld", &A, &V, &B, &W, &T);
  if (abs(A - B) > (V - W) * T) {
    printf("NO\n");
  } else
    printf("YES\n");
}
Problem p02646 (Python)

Buggy submission (status: Time Limit Exceeded):
a, v = map(int, input().split())
b, w = map(int, input().split())
t = int(input())
ans = "NO"
for i in range(t):
    if a < b:
        a += v
        b += w
    else:
        a -= v
        b -= w
    if a == b:
        ans = "YES"
        break
print(ans)


Fixed submission:
a, v = map(int, input().split())
b, w = map(int, input().split())
t = int(input())
if abs(a - b) <= (v - w) * t:
    print("YES")
else:
    print("NO")
Problem p02647 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i, n) cin >> a[i];

  rep(j, k) {
    vector<int> b(n + 1);
    rep(i, n) {
      int l, r;
      l = max(0, i - a[i]);
      r = min(n + 1, i + a[i]);
      ++b[l];
      --b[r + 1];
    }
    rep(i, n + 1) b[i + 1] += b[i];
    b.pop_back();
    if (a == b)
      break;
    else
      a = b;
  }

  rep(i, n) {
    cout << a[i];
    if (i != n - 1)
      cout << " ";
    else
      cout << endl;
  }

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i, n) cin >> a[i];

  rep(j, k) {
    vector<int> b(n + 1);
    rep(i, n) {
      int l, r;
      l = max(0, i - a[i]);
      r = min(n, i + a[i]);
      ++b[l];
      --b[r + 1];
    }
    rep(i, n + 1) b[i + 1] += b[i];
    b.pop_back();
    if (a == b)
      break;
    else
      a = b;
  }

  rep(i, n) {
    cout << a[i];
    if (i != n - 1)
      cout << " ";
    else
      cout << endl;
  }

  return 0;
}
Problem p02647 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }

  for (int i = 0; i < min(k, 50); i++) {
    vector<int> imos(n); // I'll begin the imos method
    for (int j = 0; j < n; j++) {
      int l = max(0, j - a[j]);
      int r = min(n - 1, j + a[j]);
      imos[l]++;
      // if(r+1 < n){
      imos[r + 1]--;
      //}
    }
    for (int k = 0; k < n; k++) {
      if (k > 0) {
        imos[k] += imos[k - 1];
      }
    }
    /*for(int l = 0; l < n; l++){
      a[l] = imos[l];
    }*/
    a = imos;
  }

  for (int i = 0; i < n; i++) {
    cout << a[i] << " ";
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }

  for (int i = 0; i < min(k, 50); i++) {
    vector<int> imos(n); // I'll begin the imos method
    for (int j = 0; j < n; j++) {
      int l = max(0, j - a[j]);
      int r = min(n - 1, j + a[j]);
      imos[l]++;
      if (r + 1 <= n - 1) {
        imos[r + 1]--;
      }
    }
    for (int k = 0; k < n; k++) {
      if (k > 0) {
        imos[k] += imos[k - 1];
      }
    }
    /*for(int l = 0; l < n; l++){
      a[l] = imos[l];
    }*/
    a = imos;
  }

  for (int i = 0; i < n; i++) {
    cout << a[i] << " ";
  }
}
Problem p02647 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

using ll = long long;
using namespace std;
const int INFint = 1e9 + 1;
const ll INFll = (ll)1e18 + 1;
ll MOD = 1e9 + 7;

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  for (int i(0); i < N; i++) {
    cin >> A[i];
  }
  vector<int> now = A;
  for (int i(0); i < K; i++) {
    vector<int> B(N);
    for (int j(0); j < N; j++) {
      B[max(0, j - A[j])]++;
      if (j + A[j] < N) {
        B[j + A[j] + 1]--;
      }
    }
    for (int j(1); j < N; j++) {
      B[j] += B[j - 1];
    }
    A = B;
    bool flag = true;
    for (int j(0); j < N; j++) {
      if (A[j] != N)
        flag = false;
    }
    if (flag)
      break;
  }
  for (int i(0); i < N; i++) {
    cout << A[i] << " ";
  }
  cout << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>

using ll = long long;
using namespace std;
const int INFint = 1e9 + 1;
const ll INFll = (ll)1e18 + 1;
ll MOD = 1e9 + 7;

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  for (int i(0); i < N; i++) {
    cin >> A[i];
  }
  vector<int> now = A;
  for (int i(0); i < K; i++) {
    vector<int> B(N);
    for (int j(0); j < N; j++) {
      B[max(0, j - A[j])]++;
      if (j + A[j] + 1 < N) {
        B[j + A[j] + 1]--;
      }
    }
    for (int j(1); j < N; j++) {
      B[j] += B[j - 1];
    }
    A = B;
    bool flag = true;
    for (int j(0); j < N; j++) {
      if (A[j] != N)
        flag = false;
    }
    if (flag)
      break;
  }
  for (int i(0); i < N; i++) {
    cout << A[i] << " ";
  }
  cout << endl;
  return 0;
}
Problem p02647 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

// #define int long long
typedef long long ll;
// const int INF = 2e9;
// const ll INF = 9e18;

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  for (int i = 0; i < N; i++)
    cin >> A[i];
  vector<int> state(N + 1);
  for (int k = 0; k < K; k++) {
    for (int i = 0; i < N + 1; i++) {
      state[i] = 0;
    }
    for (int i = 0; i < N; i++) {
      if (i - A[i] < 0)
        state[0]++;
      else
        state[i - A[i]]++;
      if (i + 1 + A[i] > N)
        state[N]--;
      else
        state[i + 1 + A[i]]--;
    }
    for (int i = 0; i < N; i++) {
      state[i + 1] += state[i];
    }
    for (int i = 0; i < N; i++) {
      A[i] = state[i];
    }
  }
  for (int i = 0; i < N; i++) {
    cout << A[i];
    if (i == N - 1)
      cout << "\n";
    else
      cout << " ";
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;

// #define int long long
typedef long long ll;
// const int INF = 2e9;
// const ll INF = 9e18;

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  for (int i = 0; i < N; i++)
    cin >> A[i];
  vector<int> state(N + 1);
  for (int k = 0; k < min(K, 50); k++) {
    for (int i = 0; i < N + 1; i++) {
      state[i] = 0;
    }
    for (int i = 0; i < N; i++) {
      if (i - A[i] < 0)
        state[0]++;
      else
        state[i - A[i]]++;
      if (i + 1 + A[i] > N)
        state[N]--;
      else
        state[i + 1 + A[i]]--;
    }
    for (int i = 0; i < N; i++) {
      state[i + 1] += state[i];
    }
    for (int i = 0; i < N; i++) {
      A[i] = state[i];
    }
  }
  for (int i = 0; i < N; i++) {
    cout << A[i];
    if (i == N - 1)
      cout << "\n";
    else
      cout << " ";
  }
}
Problem p02647 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#define DIM 100005
using namespace std;
int n, i, k, ok;
int a[DIM], b[DIM];
int main() {
  cin >> n >> k;
  for (i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (; k; k--) {
    for (i = 1; i <= n; i++) {
      b[max(1, i - a[i])]++;
      b[min(n + 1, i + a[i] + 1)]--;
    }
    for (i = 1; i <= n; i++) {
      b[i] += b[i - 1];
    }
    ok = 0;
    for (i = 1; i <= n; i++) {
      a[i] = b[i];
      b[i] = 0;
      if (a[i] != n) {
        ok = 1;
      }
    }
    if (ok == 0) {
      break;
    }
  }
  for (i = 1; i <= n; i++) {
    cout << a[i] << " ";
  }
}


Fixed submission:
#include <iostream>
#define DIM 200005
using namespace std;
int n, i, k, ok;
int a[DIM], b[DIM];
int main() {
  cin >> n >> k;
  for (i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (; k; k--) {
    for (i = 1; i <= n; i++) {
      b[max(1, i - a[i])]++;
      b[min(n + 1, i + a[i] + 1)]--;
    }
    for (i = 1; i <= n; i++) {
      b[i] += b[i - 1];
    }
    ok = 0;
    for (i = 1; i <= n; i++) {
      a[i] = b[i];
      b[i] = 0;
      if (a[i] != n) {
        ok = 1;
      }
    }
    if (ok == 0) {
      break;
    }
  }
  for (i = 1; i <= n; i++) {
    cout << a[i] << " ";
  }
}
Problem p02647 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  for (auto &a : A)
    cin >> a;
  for (int i = 0; i < K; i++) {
    vector<int> B(N + 1);
    for (int j = 0; j < N; j++) {
      B[max(j - A[j], 0)]++;
      B[min(j + A[j] + 1, N)]--;
    }
    for (int j = 1; j <= N; j++) {
      B[j] += B[j - 1];
    }
    swap(A, B);
    if (*min_element(A.begin(), A.end()) == N)
      break;
  }
  for (int i = 0; i < N; i++) {
    cout << A[i] << " \n"[i == N - 1];
  }
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  for (auto &a : A)
    cin >> a;
  for (int i = 0; i < K; i++) {
    vector<int> B(N + 1);
    for (int j = 0; j < N; j++) {
      B[max(j - A[j], 0)]++;
      B[min(j + A[j] + 1, N)]--;
    }
    for (int j = 1; j <= N; j++) {
      B[j] += B[j - 1];
    }
    B.pop_back();
    swap(A, B);
    if (*min_element(A.begin(), A.end()) == N)
      break;
  }
  for (int i = 0; i < N; i++) {
    cout << A[i] << " \n"[i == N - 1];
  }
}
Problem p02647 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <array>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
int gcd(int a, int b) {
  if (a % b == 0) {
    return (b);
  } else {
    return (gcd(b, a % b));
  }
}
int mod = 1000000000 + 7;
vector<int> v;
class Calc {
  // 宣言
  long long a;

public:
  // 素因数分解
  void decompositPrime(long long a);
};

/*
 * 素因数分解
 */
void Calc::decompositPrime(long long n) {
  // 割る数の初期値
  a = 2;
  // √n ≧ a ( n ≧ a * a ) の間ループ処理
  while (n >= a * a) {
    // a で割り切れたら、a は素因数
    // そして、割られる数を a で割る
    // a で割り切れなかったら、 a を 1 増加させる
    if (n % a == 0) {
      // printf("%d * ", a);
      v.push_back(a);
      n /= a;
    } else {
      a++;
    }
  }
  // 最後に残った n は素因数
  v.push_back(n);
  // printf("%d\n", n);
}

int main() {
  // std::stack<int> stack;
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int cnt = min(k, (int)log(200000) + 1);
  for (int i = 0; i < k; i++) {
    vector<int> b(n, 0);
    for (int j = 0; j < n; j++) {
      int left = max(0, j - a[j]);
      int right = min(n - 1, j + a[j]);
      b[left]++;
      if (right < n - 1) {
        b[right + 1]--;
      }
    }
    for (int j = 1; j < n; j++) {
      b[j] += b[j - 1];
    }
    a = b;
  }
  for (int i = 0; i < n - 1; i++) {
    cout << a[i] << " ";
  }
  cout << a[n - 1] << endl;
  // cout << ans << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <array>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
int gcd(int a, int b) {
  if (a % b == 0) {
    return (b);
  } else {
    return (gcd(b, a % b));
  }
}
int mod = 1000000000 + 7;
vector<int> v;
class Calc {
  // 宣言
  long long a;

public:
  // 素因数分解
  void decompositPrime(long long a);
};

/*
 * 素因数分解
 */
void Calc::decompositPrime(long long n) {
  // 割る数の初期値
  a = 2;
  // √n ≧ a ( n ≧ a * a ) の間ループ処理
  while (n >= a * a) {
    // a で割り切れたら、a は素因数
    // そして、割られる数を a で割る
    // a で割り切れなかったら、 a を 1 増加させる
    if (n % a == 0) {
      // printf("%d * ", a);
      v.push_back(a);
      n /= a;
    } else {
      a++;
    }
  }
  // 最後に残った n は素因数
  v.push_back(n);
  // printf("%d\n", n);
}

int main() {
  // std::stack<int> stack;
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int cnt = min(k, (int)log(200000) + 1);
  for (int i = 0; i < k; i++) {
    vector<int> b(n, 0);
    for (int j = 0; j < n; j++) {
      int left = max(0, j - a[j]);
      int right = min(n - 1, j + a[j]);
      b[left]++;
      if (right < n - 1) {
        b[right + 1]--;
      }
    }
    for (int j = 1; j < n; j++) {
      b[j] += b[j - 1];
    }
    if (a == b) {
      break;
    }
    a = b;
  }
  for (int i = 0; i < n - 1; i++) {
    cout << a[i] << " ";
  }
  cout << a[n - 1] << endl;
  // cout << ans << endl;
  return 0;
}
Problem p02647 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }

  vector<int> b(N, N);
  vector<int> B(N);
  while (1) {
    for (int i = 0; i < N; i++) {
      int a = A[i];
      for (int j = max(0, i - a); j <= min(N - 1, i + a); j++) {
        B[j]++;
      }
    }
    K--;
    if (K <= 0 || B == b)
      break;
    A = B;
    B = vector<int>(N);
  }

  for (int i = 0; i < N; i++) {
    if (i)
      cout << " ";
    cout << B[i];
  }
  cout << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }

  vector<int> b(N, N);
  vector<int> B(N);
  while (1) {
    for (int i = 0; i < N; i++) {
      int l = max(0, i - A[i]);
      int r = min(N - 1, i + A[i]);
      B[l]++;
      if (r + 1 < N)
        B[r + 1]--;
    }
    for (int i = 1; i < N; i++) {
      B[i] += B[i - 1];
    }
    K--;
    if (K <= 0 || B == b)
      break;
    A = B;
    B = vector<int>(N);
  }

  for (int i = 0; i < N; i++) {
    if (i)
      cout << " ";
    cout << B[i];
  }
  cout << endl;
}
Problem p02647 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < n; i++)
#define repn(i, n) for (int i = 1; i <= n; i++)
#define LL long long
#define pii pair<int, int>
#define fi first
#define se second
#define pb push_back
#define mpr make_pair

using namespace std;

const LL MOD = 1e9 + 7;

int n, k, a[100010], b[100010];

int main() {
  cin >> n >> k;
  rep(i, n) scanf("%d", &a[i]);
  rep(i, k) {
    memset(b, 0, sizeof(b));
    rep(j, n) {
      b[max(0, j - a[j])]++;
      b[min(n, j + a[j] + 1)]--;
    }
    int cur = 0, ok = 1;
    rep(j, n) {
      cur += b[j];
      if (cur < n)
        ok = 0;
      a[j] = cur;
    }
    if (ok)
      break;
  }
  rep(i, n) printf("%d ", a[i]);
  cout << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < n; i++)
#define repn(i, n) for (int i = 1; i <= n; i++)
#define LL long long
#define pii pair<int, int>
#define fi first
#define se second
#define pb push_back
#define mpr make_pair

using namespace std;

const LL MOD = 1e9 + 7;

int n, k, a[200010], b[200010];

int main() {
  cin >> n >> k;
  rep(i, n) scanf("%d", &a[i]);
  rep(i, k) {
    memset(b, 0, sizeof(b));
    rep(j, n) {
      b[max(0, j - a[j])]++;
      b[min(n, j + a[j] + 1)]--;
    }
    int cur = 0, ok = 1;
    rep(j, n) {
      cur += b[j];
      if (cur < n)
        ok = 0;
      a[j] = cur;
    }
    if (ok)
      break;
  }
  rep(i, n) printf("%d ", a[i]);
  cout << endl;
  return 0;
}
Problem p02647 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>

using namespace std;

int main(void) {
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }

  while (K--) {
    if (count(A.begin(), A.end() - 1, N) == N)
      break;
    vector<int> tmp(N + 1);
    for (int i = 0; i < N; i++) {
      tmp[max(0, i - A[i])]++;
      tmp[min(N, i + A[i] + 1)]--;
    }
    tmp.pop_back();
    partial_sum(tmp.begin(), tmp.end(), A.begin());
  }

  for (auto e : A) {
    cout << e << endl;
  }
  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>

using namespace std;

int main(void) {
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }

  while (K--) {
    if (count(A.begin(), A.end(), N) == N)
      break;
    vector<int> tmp(N + 1);
    for (int i = 0; i < N; i++) {
      tmp[max(0, i - A[i])]++;
      tmp[min(N, i + A[i] + 1)]--;
    }
    tmp.pop_back();
    partial_sum(tmp.begin(), tmp.end(), A.begin());
  }

  for (auto e : A) {
    cout << e << endl;
  }
  return 0;
}
Problem p02647 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>

using namespace std;

int main(void) {
  int N, K;
  cin >> N >> K;
  vector<int> A(N + 1);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }

  while (K--) {
    vector<int> tmp(N + 1);
    for (int i = 0; i < N; i++) {
      tmp[max(0, i - A[i])]++;
      tmp[min(N, i + A[i]) + 1]--;
    }
    partial_sum(tmp.begin(), tmp.end(), tmp.begin());
    A = tmp;
    if (count(A.begin(), A.end() - 1, N) == N)
      break;
  }
  for (int i = 0; i < N; i++) {
    cout << A[i] << endl;
  }
  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>

using namespace std;

int main(void) {
  int N, K;
  cin >> N >> K;
  vector<int> A(N + 1);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }

  while (K--) {
    vector<int> tmp(N + 1);
    for (int i = 0; i < N; i++) {
      tmp[max(0, i - A[i])]++;
      tmp[min(N, i + A[i] + 1)]--;
    }
    partial_sum(tmp.begin(), tmp.end(), tmp.begin());
    A = tmp;
    if (count(A.begin(), A.end() - 1, N) == N)
      break;
  }
  for (int i = 0; i < N; i++) {
    cout << A[i] << endl;
  }
  return 0;
}
Problem p02647 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
using ll = long long;
using P = pair<int, int>;
ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
ll LCM(ll a, ll b) { return a / GCD(a, b) * b; }

ll n, k;

int main() {
  cin >> n >> k;
  vector<ll> A(n, 0);
  for (int i = 0; i < n; ++i) {
    cin >> A.at(i);
  }

  while (k--) {
    vector<ll> B(400400, 0);
    for (int i = 0; i < n; ++i) {
      ll left = i - A.at(i);
      ll right = i + A.at(i);
      B.at(max(0LL, left))++;
      B.at(right + 1)--;
    }
    for (int i = 0; i < n; ++i) {
      B.at(i + 1) += B.at(i);
    }
    A = B;
  }

  for (int i = 0; i < n; ++i) {
    if (i == n - 1)
      cout << A.at(i) << endl;
    else
      cout << A.at(i) << " ";
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
using ll = long long;
using P = pair<int, int>;
ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
ll LCM(ll a, ll b) { return a / GCD(a, b) * b; }

ll n, k;

int main() {
  cin >> n >> k;
  vector<ll> A(n, 0);
  for (int i = 0; i < n; ++i) {
    cin >> A.at(i);
  }

  for (int i = 0; i < min(k, 45LL); ++i) {
    vector<ll> B(400400, 0);
    for (int i = 0; i < n; ++i) {
      ll left = i - A.at(i);
      ll right = i + A.at(i);
      B.at(max(0LL, left))++;
      B.at(right + 1)--;
    }
    for (int i = 0; i < n; ++i) {
      B.at(i + 1) += B.at(i);
    }
    A = B;
  }

  for (int i = 0; i < n; ++i) {
    if (i == n - 1)
      cout << A.at(i) << endl;
    else
      cout << A.at(i) << " ";
  }
}
Problem p02647 (Python)

Buggy submission (status: Time Limit Exceeded):
import sys
import numpy as np
from numba import njit

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10**8)
INF = float("inf")
MOD = 10**9 + 7


@njit("i8[:](i8,i8,i8[:])", cache=True)
def func(n, k, A):
    for _ in range(k):
        B = np.zeros(n + 1, np.int64)
        for i, a in enumerate(A):
            B[max(0, i - a)] += 1
            B[min(i + a + 1, n)] -= 1
        A = B.cumsum()[:-1]
    return A


def main():
    N, K = map(int, readline().split())
    A = np.array(readline().split(), np.int64)
    ans = func(N, K, A)
    print(*ans)


if __name__ == "__main__":
    main()


Fixed submission:
import sys
import numpy as np
from numba import njit

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10**8)
INF = float("inf")
MOD = 10**9 + 7


@njit("i8[:](i8,i8,i8[:])", cache=True)
def func(n, k, A):
    for _ in range(k):
        B = np.zeros(n + 1, np.int64)
        for i, a in enumerate(A):
            B[max(0, i - a)] += 1
            B[min(i + a + 1, n)] -= 1
        A = B.cumsum()[:-1]
        if np.all(A == n):
            break
    return A


def main():
    N, K = map(int, readline().split())
    A = np.array(readline().split(), np.int64)
    ans = func(N, K, A)
    print(*ans)


if __name__ == "__main__":
    main()
Problem p02647 (Python)

Buggy submission (status: Time Limit Exceeded):
import sys

sys.setrecursionlimit(10**7)

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, K = map(int, input().split())
A = list(map(int, input().split()))

K = min(K, 50)

for _ in range(K):
    imos = [0] * (N + 1)

    for i in range(N):
        a = A[i]
        s = max(0, i - a)
        e = min(N, i + a + 1)
        imos[s] += 1
        imos[e] -= 1

    nxt = [0] * N
    t = 0
    for i in range(N):
        t += imos[i]
        nxt[i] = t

    A = nxt

print(" ".join(map(str, A)))


Fixed submission:
import sys

sys.setrecursionlimit(10**7)

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, K = map(int, input().split())
A = list(map(int, input().split()))

K = min(K, 100)

for _ in range(K):
    imos = [0] * (N + 1)

    for i in range(N):
        a = A[i]
        s = max(0, i - a)
        e = min(N, i + a + 1)
        imos[s] += 1
        imos[e] -= 1

    nxt = [0] * N
    t = 0
    for i in range(N):
        t += imos[i]
        nxt[i] = t

    A = nxt

print(" ".join(map(str, A)))
Problem p02647 (Python)

Buggy submission (status: Runtime Error):
N, K = map(int, input().split())
A = list(map(int, input().split()))

for _ in range(min(K, 50)):
    lamp = [0 for i in range(N + 1)]
    for i in range(N):
        lamp[max(0, i - A[i])] += 1
        lamp[min(N, i + A[i] + 1)] -= 1

    for i in range(N):
        lamp[i] += lamp[i - 1]
    A = lamp

[print(A[i], end=" ") for i in range(N)]
print()


Fixed submission:
N, K = map(int, input().split())
A = list(map(int, input().split()))

for _ in range(min(K, 50)):
    lamp = [0 for i in range(N + 1)]
    for i in range(N):
        lamp[max(0, i - A[i])] += 1
        lamp[min(N, i + A[i] + 1)] -= 1

    for i in range(1, N + 1):
        lamp[i] += lamp[i - 1]
    A = lamp

[print(A[i], end=" ") for i in range(N)]
print()
Problem p02647 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define endl "\n"
#define ll long long
#define sz(s) (int)(s.size())
#define INF 0x3f3f3f3f3f3f3f3fLL
#define all(v) v.begin(), v.end()
#define watch(x) cout << (#x) << " = " << x << endl
const int dr[]{-1, -1, 0, 1, 1, 1, 0, -1};
const int dc[]{0, 1, 1, 1, 0, -1, -1, -1};
#if __cplusplus >= 201402L
template <typename T> vector<T> create(size_t n) { return vector<T>(n); }
template <typename T, typename... Args> auto create(size_t n, Args... args) {
  return vector<decltype(create<T>(args...))>(n, create<T>(args...));
}
#endif
void run() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
#ifdef EZZAT
  freopen("input.in", "r", stdin);
  // freopen("output.out", "w", stdout);
#else
#endif
}

int main() {
  run();
  int n, k;
  cin >> n >> k;
  vector<int> v(n + 1), up(n + 1);
  for (int i = 0; i < n; i++)
    cin >> v[i];
  while (k--) {
    for (int i = 0; i < n; i++) {
      up[max(i - v[i], 0)]++;
      up[min(i + v[i] + 1, n)]--;
    }
    int sum = 0;
    for (int i = 0; i < n; i++) {
      v[i] = (sum += up[i]);
      up[i] = 0;
    }
    if (*min_element(all(v)) == n)
      break;
  }
  for (int i = 0; i < n; i++)
    cout << v[i] << ' ';
}


Fixed submission:
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define endl "\n"
#define ll long long
#define sz(s) (int)(s.size())
#define INF 0x3f3f3f3f3f3f3f3fLL
#define all(v) v.begin(), v.end()
#define watch(x) cout << (#x) << " = " << x << endl
const int dr[]{-1, -1, 0, 1, 1, 1, 0, -1};
const int dc[]{0, 1, 1, 1, 0, -1, -1, -1};
#if __cplusplus >= 201402L
template <typename T> vector<T> create(size_t n) { return vector<T>(n); }
template <typename T, typename... Args> auto create(size_t n, Args... args) {
  return vector<decltype(create<T>(args...))>(n, create<T>(args...));
}
#endif
void run() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
#ifdef EZZAT
  freopen("input.in", "r", stdin);
  // freopen("output.out", "w", stdout);
#else
#endif
}

int main() {
  run();
  int n, k;
  cin >> n >> k;
  vector<int> v(n), up(n + 1);
  for (int i = 0; i < n; i++)
    cin >> v[i];
  while (k--) {
    for (int i = 0; i < n; i++) {
      up[max(i - v[i], 0)]++;
      up[min(i + v[i] + 1, n)]--;
    }
    int sum = 0;
    for (int i = 0; i < n; i++) {
      v[i] = (sum += up[i]);
      up[i] = 0;
    }
    if (*min_element(all(v)) == n)
      break;
  }
  for (int i = 0; i < n; i++)
    cout << v[i] << ' ';
}
Problem p02647 (C++)

Buggy submission (status: Time Limit Exceeded):
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;
const ll MOD = 1000000007;
const double pi = acos(-1);

int main() {
  ll N, K;
  cin >> N >> K;
  vector<ll> A(N);
  rep(i, N) { cin >> A.at(i); }
  rep(i, min(K, (ll)1000)) {
    vector<ll> hoge(N, 0);
    vector<ll> sirusi(N, 0);
    rep(i, N) {
      sirusi.at(max((ll)0, i - A.at(i)))++;
      if (i + A.at(i) < N - 1) {
        sirusi.at(i + A.at(i) + 1)--;
      }
    }
    rep(i, N) {
      if (i == 0) {
        hoge.at(0) = sirusi.at(0);
        continue;
      }
      hoge.at(i) = hoge.at(i - 1) + sirusi.at(i);
    }
    A = hoge;
  }
  rep(i, N) {
    if (i != 0) {
      cout << " ";
    }
    cout << A.at(i);
  }
  cout << endl;
  return 0;
}


Fixed submission:
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;
const ll MOD = 1000000007;
const double pi = acos(-1);

int main() {
  ll N, K;
  cin >> N >> K;
  vector<ll> A(N);
  rep(i, N) { cin >> A.at(i); }
  rep(i, min(K, (ll)100)) {
    vector<ll> hoge(N, 0);
    vector<ll> sirusi(N, 0);
    rep(i, N) {
      sirusi.at(max((ll)0, i - A.at(i)))++;
      if (i + A.at(i) < N - 1) {
        sirusi.at(i + A.at(i) + 1)--;
      }
    }
    rep(i, N) {
      if (i == 0) {
        hoge.at(0) = sirusi.at(0);
        continue;
      }
      hoge.at(i) = hoge.at(i - 1) + sirusi.at(i);
    }
    A = hoge;
  }
  rep(i, N) {
    if (i != 0) {
      cout << " ";
    }
    cout << A.at(i);
  }
  cout << endl;
  return 0;
}
Problem p02647 (C++)

Buggy submission (status: Runtime Error):
/**
 *    created: 13.06.2020 21:08:42
 **/
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;

signed main() {

  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i, n) cin >> a[k];
  rep(ki, k) {
    vector<int> b(n + 1);
    rep(i, n) {
      int l = max(0, i - a[i]);
      int r = min(i + a[i] + 1, n);
      b[l]++;
      b[r]--;
    }
    rep(i, n) b[i + 1] += b[i];
    b.pop_back();
    if (a == b)
      break;
    a = b;
  }
  rep(i, n) cout << a[i] << endl;
  return 0;
}

Fixed submission:
/**
 *    created: 13.06.2020 21:08:42
 **/
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;

signed main() {

  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  rep(ki, k) {
    vector<int> b(n + 1);
    rep(i, n) {
      int l = max(0, i - a[i]);
      int r = min(i + a[i] + 1, n);
      b[l]++;
      b[r]--;
    }
    rep(i, n) b[i + 1] += b[i];
    b.pop_back();
    if (a == b)
      break;
    a = b;
  }
  rep(i, n) cout << a[i] << endl;
  return 0;
}