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

#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (ll i = a; i < b; ++i)
#define IOS                                                                    \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define endl "\\n"
#define pb push_back
#define F first
#define S second
#define print(a)                                                               \\
  for (auto x : a)                                                             \\
    cout << x << " ";                                                          \\
  cout << endl
#define print1(a)                                                              \\
  for (auto x : a)                                                             \\
  cout << x.F << " " << x.S << endl
#define print2(a, x, y)                                                        \\
  for (int i = x; i < y; i++)                                                  \\
    cout << a[i] << " ";                                                       \\
  cout << endl
#define mk(x, y) make_pair(x, y)
typedef long long int ll;
const int N = (2e6 + 5);
const int mod = 1e9 + 7;
ll n, a[N], k, c, l[N], r[N];

ll pow_mod_m(ll a, ll n) {
  if (!n)
    return 1;
  ll pt = pow_mod_m(a, n / 2);
  pt *= pt;
  pt %= mod;
  if (n & 1)
    pt *= a, pt %= mod;
  return pt;
}

int main() {
  IOS;
  //     freopen("a_example (2).txt","r",stdin);
  //     freopen("c.txt","w",stdout);

  int ts = 1;
  //  cin>>ts;
  while (ts--) {
    cin >> n >> k >> c;
    string s;
    cin >> s;
    vector<ll> v;
    rep(i, 0, n) {
      if (s[i] == 'o')
        v.pb(i + 1);
    }
    int z = 0;
    rep(i, 0, v.size()) {
      if (i == 0)
        l[z++] = v[0];
      else if (v[i] - l[z - 1] > c and z < k) {
        l[z++] = v[i];
      }
    }
    z = k - 1;
    for (int i = v.size() - 1; i >= 0; i--) {
      if (i == v.size() - 1)
        r[z--] = v[v.size() - 1];
      else if (r[z + 1] - v[i] > c and z >= 0) {
        r[z--] = v[i];
      }
    }
    rep(i, 0, k) {
      if (l[i] == r[i])
        cout << l[i] << endl;
    }
  }
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (ll i = a; i < b; ++i)
#define IOS                                                                    \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define endl "\\n"
#define pb push_back
#define F first
#define S second
#define print(a)                                                               \\
  for (auto x : a)                                                             \\
    cout << x << " ";                                                          \\
  cout << endl
#define print1(a)                                                              \\
  for (auto x : a)                                                             \\
  cout << x.F << " " << x.S << endl
#define print2(a, x, y)                                                        \\
  for (int i = x; i < y; i++)                                                  \\
    cout << a[i] << " ";                                                       \\
  cout << endl
#define mk(x, y) make_pair(x, y)
typedef long long int ll;
const int N = (2e6 + 5);
const int mod = 1e9 + 7;
ll n, a[N], k, c, l[N], r[N];

ll pow_mod_m(ll a, ll n) {
  if (!n)
    return 1;
  ll pt = pow_mod_m(a, n / 2);
  pt *= pt;
  pt %= mod;
  if (n & 1)
    pt *= a, pt %= mod;
  return pt;
}

int main() {
  IOS;
  //     freopen("a_example (2).txt","r",stdin);
  //     freopen("c.txt","w",stdout);

  int ts = 1;
  //  cin>>ts;
  while (ts--) {
    cin >> n >> k >> c;
    string s;
    cin >> s;
    vector<ll> v;
    rep(i, 0, n) {
      if (s[i] == 'o')
        v.pb(i + 1);
    }
    int z = 0;
    rep(i, 0, v.size()) {
      if (i == 0)
        l[z++] = v[0];
      else if (v[i] - l[z - 1] > c) {
        l[z++] = v[i];
      }
    }
    z = k - 1;
    for (int i = v.size() - 1; i >= 0; i--) {
      if (i == v.size() - 1)
        r[z--] = v[v.size() - 1];
      else if (r[z + 1] - v[i] > c) {
        r[z--] = v[i];
      }
    }
    rep(i, 0, k) {
      if (l[i] == r[i])
        cout << l[i] << endl;
    }
  }
}