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

#include <bits/stdc++.h>
#define int long long
#define maxn 210000
#define inf 1000000000
#define mod 1000000007
#define flash                                                                  \\
  cin.tie(0);                                                                  \\
  cout.tie(0);                                                                 \\
  ios_base::sync_with_stdio(false);
#define FILEIO                                                                 \\
  freopen(                                                                     \\
      "/home/aman/Desktop/Kachda/input.txt", "r",                              \\
      stdin); // freopen("/home/aman/Desktop/Kachda/output.txt", "w", stdout);

using namespace std;

int n, k, c, l[maxn + 1], r[maxn + 1], a[maxn + 1], b[maxn + 1];
string s;

signed main() {
  flash

          cin >>
      n >> k >> c >> s;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'o') {
      l[i] = (i >= c + 1) ? 1 + l[i - (c + 1)] : 1;
    }
    if (i)
      l[i] = max(l[i], l[i - 1]);

    if (l[i] > k)
      return cout << '\\n', 0;
  }

  reverse(s.begin(), s.end());

  for (int i = 0; i < n; i++) {
    if (s[i] == 'o') {
      r[i] = (i >= c + 1) ? 1 + r[i - (c + 1)] : 1;
    }
    if (i)
      r[i] = max(r[i], r[i - 1]);
  }

  for (int i = 0; i < n; i++)
    r[i] = k - r[i] + 1;
  reverse(r, r + n);

  for (int i = 0; i <= n; i++)
    a[i] = inf, b[i] = 0;

  for (int i = 0; i < n; i++) {
    a[l[i]] = min(a[l[i]], i + 1);
    b[r[i]] = max(b[r[i]], i + 1);
  }

  for (int i = 1; i <= k; i++) {
    if (a[i] == b[i])
      cout << a[i] << "\\n";
  }
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define int long long
#define maxn 210000
#define inf 1000000000
#define mod 1000000007
#define flash                                                                  \\
  cin.tie(0);                                                                  \\
  cout.tie(0);                                                                 \\
  ios_base::sync_with_stdio(false);
#define fileio                                                                 \\
  freopen(                                                                     \\
      "/home/aman/desktop/kachda/input.txt", "r",                              \\
      stdin); // freopen("/home/aman/desktop/kachda/output.txt", "w", stdout);
using namespace std;

int n, k, c, l[maxn + 1], r[maxn + 1], a[maxn + 1], b[maxn + 1];
string s;

signed main() {
  flash

          cin >>
      n >> k >> c >> s;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'o') {
      l[i] = (i >= c + 1) ? 1 + l[i - (c + 1)] : 1;
    }
    if (i)
      l[i] = max(l[i], l[i - 1]);
  }

  reverse(s.begin(), s.end());

  for (int i = 0; i < n; i++) {
    if (s[i] == 'o') {
      r[i] = (i >= c + 1) ? 1 + r[i - (c + 1)] : 1;
    }
    if (i)
      r[i] = max(r[i], r[i - 1]);
  }

  for (int i = 0; i < n; i++)
    r[i] = k - r[i] + 1;
  reverse(r, r + n);

  for (int i = 0; i <= n; i++)
    a[i] = inf;

  for (int i = 0; i < n; i++) {
    a[l[i]] = min(a[l[i]], i + 1);
    b[r[i]] = max(b[r[i]], i + 1);
  }

  for (int i = 1; i <= k; i++) {
    if (a[i] == b[i])
      cout << a[i] << "\\n";
  }
}