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

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
#define mkp make_pair
#define mkt make_tuple
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
template <class T> void chmin(T &a, const T &b) {
  if (a > b)
    a = b;
}
template <class T> void chmax(T &a, const T &b) {
  if (a < b)
    a = b;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int N, K, C;
  cin >> N >> K >> C;
  string S;
  cin >> S;

  vector<int> left(N + 1, 0), right(N + 1, 0);
  int ma = 0;
  for (int i = 0; i < N; i++) {
    if (i - C - 1 >= 0)
      chmax(ma, left[i - C - 1]);
    if (i > 0)
      chmax(left[i], left[i - 1]);
    if (S[i] == 'o')
      chmax(left[i], ma + 1);
  }
  ma = 0;
  for (int i = N - 1; i >= 0; i--) {
    if (i + C + 1 < N)
      chmax(ma, right[i + C + 1]);
    chmax(right[i], right[i + 1]);
    if (S[i] == 'o')
      chmax(right[i], ma + 1);
  }

  if (C == 0) {
    int s = 0;
    rep(i, N) if (S[i] == 'o') s++;
    if (s == K) {
      rep(i, N) if (S[i] == 'o') cout << i + 1 << "\\n";
    }
    return 0;
  }

  vector<int> num(N + 2 * (C + 2), 0);
  for (int i = -C; i <= N + C; i++) {
    int l = 0, r = 0;
    if (i >= 0 && i < N)
      l = left[i];
    if (i + C + 1 < N && i + C + 1 >= 0)
      r = right[i + C + 1];
    num[i + C] = l + r;
  }

  vector<int> ans;
  set<pair<int, int>> se;
  for (int i = 0; i < C; i++)
    se.insert(mkp(-num[i], i));
  for (int i = 0; i < N; i++) {
    auto itr = se.begin();
    int val = -(*itr).first;
    if (val < K && S[i] == 'o')
      ans.push_back(i + 1);

    se.erase(mkp(-num[i], i));
    se.insert(mkp(-num[i + C], i + C));
  }

  for (auto n : ans)
    cout << n << "\\n";

  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
#define mkp make_pair
#define mkt make_tuple
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
template <class T> void chmin(T &a, const T &b) {
  if (a > b)
    a = b;
}
template <class T> void chmax(T &a, const T &b) {
  if (a < b)
    a = b;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int N, K, C;
  cin >> N >> K >> C;
  string S;
  cin >> S;

  vector<int> left(N + 1, 0), right(N + 1, 0);
  int ma = 0;
  for (int i = 0; i < N; i++) {
    if (i - C - 1 >= 0)
      chmax(ma, left[i - C - 1]);
    if (i > 0)
      chmax(left[i], left[i - 1]);
    if (S[i] == 'o')
      chmax(left[i], ma + 1);
  }
  ma = 0;
  for (int i = N - 1; i >= 0; i--) {
    if (i + C + 1 < N)
      chmax(ma, right[i + C + 1]);
    chmax(right[i], right[i + 1]);
    if (S[i] == 'o')
      chmax(right[i], ma + 1);
  }

  if (C == 0) {
    int s = 0;
    rep(i, N) if (S[i] == 'o') s++;
    if (s == K) {
      rep(i, N) if (S[i] == 'o') cout << i + 1 << "\\n";
    }
    return 0;
  }

  vector<int> num(N + 2 * (C + 1), 0);
  for (int i = -C; i <= N + C; i++) {
    int l = 0, r = 0;
    if (i >= 0)
      l = left[i];
    if (i + C + 1 < N)
      r = right[i + C + 1];
    num[i + C] = l + r;
  }

  vector<int> ans;
  set<pair<int, int>> se;
  for (int i = 0; i < C; i++)
    se.insert(mkp(-num[i], i));
  for (int i = 0; i < N; i++) {
    auto itr = se.begin();
    int val = -(*itr).first;
    if (val < K && S[i] == 'o')
      ans.push_back(i + 1);

    se.erase(mkp(-num[i], i));
    se.insert(mkp(-num[i + C], i + C));
  }

  for (auto n : ans)
    cout << n << "\\n";

  return 0;
}