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

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
#define For(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) For(i, 0, n)
#define debug(x) cerr << #x << " = " << (x) << endl;
#define leftunique(a)                                                          \\
  {                                                                            \\
    sort((a).begin(), (a).end());                                              \\
    (a).erase(unique((a).begin(), (a).end()), (a).end());                      \\
  }
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
static const ll INF = 1LL << 60;
// Write From this Line

int a[200010], b[200010];
int main() {
  // input
  int n, k, c;
  string s;
  cin >> n >> k >> c;
  ll ans = 0;
  cin >> s;

  // solve
  int cnt = 0;
  rep(i, n) {
    if (s[i] == 'o') {
      a[cnt++] = i;
      i += c;
    }
  }
  cnt = 0;
  for (int i = n - 1; i >= 0; --i) {
    if (s[i] == 'o') {
      b[cnt++] = i;
      i -= c;
    }
  }

  rep(i, k) {
    if (a[i] == b[k - i - 1]) {
      cout << a[i] + 1 << endl;
    }
  }
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
#define For(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) For(i, 0, n)
#define debug(x) cerr << #x << " = " << (x) << endl;
#define leftunique(a)                                                          \\
  {                                                                            \\
    sort((a).begin(), (a).end());                                              \\
    (a).erase(unique((a).begin(), (a).end()), (a).end());                      \\
  }
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
static const ll INF = 1LL << 60;
// Write From this Line

int main() {
  ll n, k, c;
  cin >> n >> k >> c;
  string s;
  cin >> s;
  ll work = 0; // 働ける日が何日あるか。
  vector<ll> dp(100100, -1);
  dp[0] = 0;
  ll plz_rest = 0;
  map<ll, bool> mp;
  vector<ll> husime(0);
  for (int i = 1; i <= n + n; i++) {
    // 文字は i - 1文字目を見る
    if (i > n) {
      dp[i] = dp[i - 1];
      continue;
    }
    if (i <= plz_rest) {
      dp[i] = dp[i - 1];
      continue;
    }

    if (s[i - 1] == 'o') {
      dp[i] = dp[i - 1] + 1;
      mp[i] = true;
      husime.push_back(i);
      plz_rest = i + c;
    } else {
      dp[i] = dp[i - 1];
    }
  }

  vector<ll> work_day(n + 100100, 0); // 働ける日が累積何日か
  rep(i, n + n) {
    if (i > n) {
      dp[i + 1] = dp[i];
      continue;
    }
    if (s[i] == 'o') {
      work_day[i + 1] = work_day[i] + 1;
    } else {
      work_day[i + 1] = work_day[i];
    }
  }
  ll can_work = dp[n]; // 最大で働ける回数
  if (can_work >= k + 1)
    return 0; // どこも働くべき日にちはない
  // それ以外というのは必ずcan_work == k （つまり,次のroop内はcan_work ==
  // kと考えて良い。

  ll count = 0; // 節目を見るもの
  for (int i = 1; i <= n; i++) {
    if (s[i - 1] == 'x')
      continue;
    if (s[i - 1] == 'o') {
      // dpの値の変わり目だったら注意
      if (dp[i - 1] != dp[i]) {
        ll next = husime[++count];
        if (count == husime.size()) {
          cout << i << endl;
          continue;
        }
        // next - 1 -cまでに働ける日があればいい
        if (dp[i] == work_day[next - 1]) {
          if (work_day[i] != work_day[next - 1 - c]) {
            // ok
            continue;
          } else {
            cout << i << endl;
            continue;
          }
        } else {
          cout << i << endl;
        }

        // 調べる必要がある
        // i + c日目まで休まなければいけない。
      }
    }
  }
}