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

//  __      __       .__           .____________                   __________ __
//  ________   __
// /  \\    /  \\ ____ |_________  __| _\\______   \\__ __  ____  _____\\______   \\__
// ___/  |\\_____  \\ |  | ______  ___.__. \\   \\/\\/   _/ __ \\|  \\_  __ \\/ __ | |
// |  _|  |  \\/ ___\\/  ___/|    |  _|  |  \\   __/   |   \\|  |/ \\__  \\<   |  |
//  \\        /\\  ___/|  ||  | \\/ /_/ | |    |   |  |  / /_/  \\___ \\ |    |   |
//  |  /|  |/    |    |    < / __ \\\\___  |
//   \\__/\\  /  \\___  |__||__|  \\____ | |______  |____/\\___  /____  >|______
//   |____/ |__|\\_______  |__|_ (____  / ____|
//        \\/       \\/               \\/        \\/     /_____/     \\/        \\/ \\/
//        \\/    \\/\\/

#include <bits/stdc++.h>

#define ll long long
#define ld long double
#define ff first
#define ss second
#define PI 3.14159265358979323846
#define endl '\\n'

using namespace std;

void solve() {
  int n, k, c;
  cin >> n >> k >> c;
  string s;
  cin >> s;
  int L[k], R[k];
  int p = -1, cp = 0;
  for (int i = 0; i < n, cp < k; i++)
    if (s[i] == 'o') {
      if (p == -1) {
        L[cp] = i;
        cp++;
        p = i;
      } else if (i - p > c) {
        L[cp] = i;
        cp++;
        p = i;
      }
    }
  p = n + 1, cp = k - 1;
  for (int i = n - 1; i >= 0, cp >= 0; i--)
    if (s[i] == 'o') {
      if (p == n + 1) {
        R[cp] = i;
        cp--;
        p = i;
      } else if (p - i > c) {
        R[cp] = i;
        cp--;
        p = i;
      }
    }
  vector<int> ans;
  for (int i = 0; i < k; i++)
    if (L[i] == R[i])
      ans.push_back(L[i] + 1);
  for (auto i : ans)
    cout << i << endl;
}

int main() {
  int q = 1;
  // scanf("%d", &q);
  for (int i = 1; i <= q; i++) {
    solve();
  }
  return 0;
}

Error: 0

Fixed submission:

//  __      __       .__           .____________                   __________ __
//  ________   __
// /  \\    /  \\ ____ |_________  __| _\\______   \\__ __  ____  _____\\______   \\__
// ___/  |\\_____  \\ |  | ______  ___.__. \\   \\/\\/   _/ __ \\|  \\_  __ \\/ __ | |
// |  _|  |  \\/ ___\\/  ___/|    |  _|  |  \\   __/   |   \\|  |/ \\__  \\<   |  |
//  \\        /\\  ___/|  ||  | \\/ /_/ | |    |   |  |  / /_/  \\___ \\ |    |   |
//  |  /|  |/    |    |    < / __ \\\\___  |
//   \\__/\\  /  \\___  |__||__|  \\____ | |______  |____/\\___  /____  >|______
//   |____/ |__|\\_______  |__|_ (____  / ____|
//        \\/       \\/               \\/        \\/     /_____/     \\/        \\/ \\/
//        \\/    \\/\\/

#include <bits/stdc++.h>

#define ll long long
#define ld long double
#define ff first
#define ss second
#define PI 3.14159265358979323846
#define endl '\\n'

using namespace std;

void solve() {
  int n, k, c;
  cin >> n >> k >> c;
  string s;
  cin >> s;
  int L[k], R[k];
  int p = -1, cp = 0;
  for (int i = 0; i < n; i++)
    if (s[i] == 'o') {
      if (p == -1) {
        L[cp] = i;
        cp++;
        p = i;
      } else if (i - p > c) {
        L[cp] = i;
        cp++;
        p = i;
      }
    }
  p = n + 1, cp = k - 1;
  for (int i = n - 1; i >= 0; i--)
    if (s[i] == 'o') {
      if (p == n + 1) {
        R[cp] = i;
        cp--;
        p = i;
      } else if (p - i > c) {
        R[cp] = i;
        cp--;
        p = i;
      }
    }
  vector<int> ans;
  for (int i = 0; i < k; i++)
    if (L[i] == R[i])
      ans.push_back(L[i] + 1);
  for (auto i : ans)
    cout << i << endl;
}

int main() {
  int q = 1;
  // scanf("%d", &q);
  for (int i = 1; i <= q; i++) {
    solve();
  }
  return 0;
}