Problem p02721 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define DEBUG(x)                                                               \
  cerr << "line:" << __LINE__ << ", " << #x " == " << (x) << endl;
#define REP(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
#define FOR(it, s) for (__typeof(s.begin()) it = s.begin(); it != s.end(); it++)
#define fst first
#define snd second
#define ALL(a) a.begin(), a.end()
#define RI(x) scanf("%d", &(x))
#define RII(x, y) scanf("%d%d", &(x), &(y))
#define RIII(x, y, z) scanf("%d%d%d", &(x), &(y), &(z))
#define DRI(x)                                                                 \
  int(x);                                                                      \
  scanf("%d", &(x))
#define DRII(x, y)                                                             \
  int(x), (y);                                                                 \
  scanf("%d%d", &(x), &(y))
#define DRIII(x, y, z)                                                         \
  int(x), (y), (z);                                                            \
  scanf("%d%d%d", &(x), &(y), &(z))
using namespace std;

typedef long long LL;
typedef unsigned int uint;
typedef unsigned long long ULL;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<vi> vvi;
struct Point {
  int x, y;
  Point(int x = 0, int y = 0) : x(x), y(y) {}
};
typedef Point Vector;
#define INF (int)1e9
#define EPS (1.0e-8)
LL gcd(LL a, LL b) { return !b ? a : gcd(b, a % b); }
LL lcm(LL a, LL b) { return a / gcd(a, b) * b; }
LL qpow(LL a, LL b) {
  LL res = 1;
  while (b > 0) {
    if (b & 1)
      res = res * a;
    a = a * a;
    b >>= 1;
  }
  return res;
}
LL qpow(LL a, LL b, LL mod) {
  a %= mod;
  LL res = 1;
  while (b > 0) {
    if (b & 1)
      res = res * a % mod;
    a = a * a % mod;
    b >>= 1;
  }
  return res;
}
// ------------------

const int maxn = 1e5 + 10;
int L[maxn], R[maxn];
int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
#ifdef LOCAL
  // freopen(".in", "r", stdin);
  // freopen(".out", "w", stdout);
#endif
  // DRIII(N, K, C);
  int N, K, C;
  cin >> N >> K >> C;
  string s;
  cin >> s;
  int cur = 0;

  REP(i, 0, K) {
    int tmp;
    if (i == 0) {
      tmp = 0;
    } else {
      tmp = C;
    }
    while (s[cur] != 'o' || tmp > 0) {
      tmp--;
      cur++;
    }
    // ok, find one
    L[i] = cur + 1;
    cur++;
  }
  // REP(i, 0, K) cout << L[i] << " "; cout << endl;

  cur = N - 1;
  for (int i = K - 1; i >= 0; i--) {
    int tmp;
    if (i == K - 1) {
      tmp = 0;
    } else {
      tmp = C;
    }
    while (s[cur] != 'o' || tmp > 0) {
      tmp--;
      cur--;
    }
    // ok, find one
    R[i] = cur + 1;
    cur--;
  }
  // REP(i, 0, K) cout << R[i] << " "; cout << endl;

  // REP(i, 0, K) if (L[i] == R[i]) cout << L[i] << ' ';
  REP(i, 0, K) if (L[i] == R[i]) cout << L[i] << endl;

#ifdef LOCAL
  cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define DEBUG(x)                                                               \
  cerr << "line:" << __LINE__ << ", " << #x " == " << (x) << endl;
#define REP(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
#define FOR(it, s) for (__typeof(s.begin()) it = s.begin(); it != s.end(); it++)
#define fst first
#define snd second
#define ALL(a) a.begin(), a.end()
#define RI(x) scanf("%d", &(x))
#define RII(x, y) scanf("%d%d", &(x), &(y))
#define RIII(x, y, z) scanf("%d%d%d", &(x), &(y), &(z))
#define DRI(x)                                                                 \
  int(x);                                                                      \
  scanf("%d", &(x))
#define DRII(x, y)                                                             \
  int(x), (y);                                                                 \
  scanf("%d%d", &(x), &(y))
#define DRIII(x, y, z)                                                         \
  int(x), (y), (z);                                                            \
  scanf("%d%d%d", &(x), &(y), &(z))
using namespace std;

typedef long long LL;
typedef unsigned int uint;
typedef unsigned long long ULL;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<vi> vvi;
struct Point {
  int x, y;
  Point(int x = 0, int y = 0) : x(x), y(y) {}
};
typedef Point Vector;
#define INF (int)1e9
#define EPS (1.0e-8)
LL gcd(LL a, LL b) { return !b ? a : gcd(b, a % b); }
LL lcm(LL a, LL b) { return a / gcd(a, b) * b; }
LL qpow(LL a, LL b) {
  LL res = 1;
  while (b > 0) {
    if (b & 1)
      res = res * a;
    a = a * a;
    b >>= 1;
  }
  return res;
}
LL qpow(LL a, LL b, LL mod) {
  a %= mod;
  LL res = 1;
  while (b > 0) {
    if (b & 1)
      res = res * a % mod;
    a = a * a % mod;
    b >>= 1;
  }
  return res;
}
// ------------------

const int maxn = 2e5 + 10;
int L[maxn], R[maxn];
int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
#ifdef LOCAL
  // freopen(".in", "r", stdin);
  // freopen(".out", "w", stdout);
#endif
  // DRIII(N, K, C);
  int N, K, C;
  cin >> N >> K >> C;
  string s;
  cin >> s;
  int cur = 0;

  REP(i, 0, K) {
    int tmp;
    if (i == 0) {
      tmp = 0;
    } else {
      tmp = C;
    }
    while (s[cur] != 'o' || tmp > 0) {
      tmp--;
      cur++;
    }
    // ok, find one
    L[i] = cur + 1;
    cur++;
  }
  // REP(i, 0, K) cout << L[i] << " "; cout << endl;

  cur = N - 1;
  for (int i = K - 1; i >= 0; i--) {
    int tmp;
    if (i == K - 1) {
      tmp = 0;
    } else {
      tmp = C;
    }
    while (s[cur] != 'o' || tmp > 0) {
      tmp--;
      cur--;
    }
    // ok, find one
    R[i] = cur + 1;
    cur--;
  }
  // REP(i, 0, K) cout << R[i] << " "; cout << endl;

  // REP(i, 0, K) if (L[i] == R[i]) cout << L[i] << ' ';
  REP(i, 0, K) if (L[i] == R[i]) cout << L[i] << endl;

#ifdef LOCAL
  cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
  return 0;
}