Problem p02721 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
// #pragma GCC optimize ("O3")
// #pragma GCC target ("sse4")
#define endl "\n"
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template <class T, class T2> inline bool chkmax(T &x, const T2 &y) {
  return x < y ? x = y, 1 : 0;
}
template <class T, class T2> inline bool chkmin(T &x, const T2 &y) {
  return x > y ? x = y, 1 : 0;
}
const ll mod = 1e9 + 7;
template <class T> inline void fix(T &x) {
  if (x >= mod | x <= -mod) {
    x %= mod;
  }
  if (x < 0) {
    x += mod;
  }
}

const int MAX_N = 1e5 + 10;
ll suf[MAX_N], pref[MAX_N];
int n, k, c;
string in;
bool ok[MAX_N];

signed main() {
  // ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
  cin >> n >> k >> c >> in;
  c++;
  for (int i = 0; i < n; i++) {
    if (in[i] == 'o' && i + c < n) {
      chkmax(pref[i + c], pref[i] + 1);
    }
    if (i + 1 < n) {
      chkmax(pref[i + 1], pref[i]);
    }
  }
  for (int i = n - 1; i >= 0; i--) {
    if (in[i] == 'o' && i - c >= 0) {
      chkmax(suf[i - c], suf[i] + 1);
    }
    if (i > 0) {
      chkmax(suf[i - 1], suf[i]);
    }
  }
  ll r = -1;
  for (int i = 0; i < n; i++) {
    if (pref[i] + suf[i] >= k) {
      ok[i] = true;
    }
    if (i <= r) {
      ok[i] = true;
    }
    if (in[i] == 'o' && pref[i] + suf[i] + 1 >= k) {
      r = i + c - 1;
    }
  }
  int l = n + 1;
  for (int i = n - 1; i >= 0; i--) {
    if (i >= l) {
      ok[i] = true;
    }
    if (in[i] == 'o' && pref[i] + suf[i] + 1 >= k) {
      l = i - c + 1;
    }
  }
  for (int i = 0; i < n; i++) {
    if (!ok[i]) {
      cout << i + 1 << endl;
    }
  }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
// #pragma GCC optimize ("O3")
// #pragma GCC target ("sse4")
#define endl "\n"
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template <class T, class T2> inline bool chkmax(T &x, const T2 &y) {
  return x < y ? x = y, 1 : 0;
}
template <class T, class T2> inline bool chkmin(T &x, const T2 &y) {
  return x > y ? x = y, 1 : 0;
}
const ll mod = 1e9 + 7;
template <class T> inline void fix(T &x) {
  if (x >= mod | x <= -mod) {
    x %= mod;
  }
  if (x < 0) {
    x += mod;
  }
}

const int MAX_N = 1e6 + 10;
ll suf[MAX_N], pref[MAX_N];
int n, k, c;
string in;
bool ok[MAX_N];

signed main() {
  // ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
  cin >> n >> k >> c >> in;
  c++;
  for (int i = 0; i < n; i++) {
    if (in[i] == 'o' && i + c < n) {
      chkmax(pref[i + c], pref[i] + 1);
    }
    if (i + 1 < n) {
      chkmax(pref[i + 1], pref[i]);
    }
  }
  for (int i = n - 1; i >= 0; i--) {
    if (in[i] == 'o' && i - c >= 0) {
      chkmax(suf[i - c], suf[i] + 1);
    }
    if (i > 0) {
      chkmax(suf[i - 1], suf[i]);
    }
  }
  ll r = -1;
  for (int i = 0; i < n; i++) {
    if (pref[i] + suf[i] >= k) {
      ok[i] = true;
    }
    if (i <= r) {
      ok[i] = true;
    }
    if (in[i] == 'o' && pref[i] + suf[i] + 1 >= k) {
      r = i + c - 1;
    }
  }
  int l = n + 1;
  for (int i = n - 1; i >= 0; i--) {
    if (i >= l) {
      ok[i] = true;
    }
    if (in[i] == 'o' && pref[i] + suf[i] + 1 >= k) {
      l = i - c + 1;
    }
  }
  for (int i = 0; i < n; i++) {
    if (!ok[i]) {
      cout << i + 1 << endl;
    }
  }
  return 0;
}