Problem p02852 (C++)

Buggy submission (status: Time Limit Exceeded):
//  |. . . . . . . . . .|       NEXT
//  |. . . . . . . . . .|      ______
//  |. . . . . . . . . .|     |      |
//  |. . . . . . . . . .|     |  OO  |
//  |. . . . . . . . . .|     |  OO  |
//  |. . . . . . . . . .|     |______|
//  |. . . . I . . . . .|
//  |. . . . I . . . . .|
//  |. . . . I . . . . .|     PLAYER
//  |. . . . I . . . . .|    STYXCEL
//  |. . . . . . . . . .|
//  |I J J J . T T T S S|      LINES
//  |I J O O . L T S S T|          0
//  |I L O O . L Z Z T T|      SCORE
//  |I L L L . L L Z Z T|      00021

#include <bits/stdc++.h>

using namespace std;
// #pragma GCC optimize ("O2,unroll-loops")
// #pragma GCC target ("tune=native")

#define ll long long
#define ull unsigned long long
#define ld long double
#define vi vector<ll>
#define vii vector<vector<ll>>
#define fr() front()
#define bc() back()
#define pushb push_back
#define popb pop_backtop

#define pii pair<ll, ll>
#define piii pair<pair<ll, ll>, ll>
#define fi first
#define se second
#define ff fi.fi
#define fs fi.se
#define sf se.fi
#define ss se.se
#define psplit(pp, a, b) (a = pp.fi, b = pp.se);
#define ppsplit(ppp, a, b, c) (a = ppp.fi.fi, b = ppp.fi.se, c = ppp.se);

#define endl ("\n")
const ll INF = 1 << 30;
const ll LINF = 1 << 62;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;

int main() {

  // freopen("inp.txt","r",stdin);
  // freopen("out.txt","w",stdout);
  // ios::sync_with_stdio(false);
  // cin.tie(0);
  // cout.tie(0);

  int n = 0, m = 0;
  string s;

  cin >> n >> m;
  cin >> s;
  int ye = 0;
  stack<int> jumps;
  int cur = n;
  while (cur > 0) {
    for (int i = m; i > 0; i--) {
      if (cur - i >= 0 && s[cur - i] == '0') {
        jumps.push(i);
        cur -= i;
        ye = 1;
        break;
      }
    }
    if (!ye) {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << jumps.top();
  jumps.pop();
  while (!jumps.empty()) {
    cout << " " << jumps.top();
    jumps.pop();
  }
  cout << endl;
  return 0;
}

Fixed submission:
//  |. . . . . . . . . .|       NEXT
//  |. . . . . . . . . .|      ______
//  |. . . . . . . . . .|     |      |
//  |. . . . . . . . . .|     |  OO  |
//  |. . . . . . . . . .|     |  OO  |
//  |. . . . . . . . . .|     |______|
//  |. . . . I . . . . .|
//  |. . . . I . . . . .|
//  |. . . . I . . . . .|     PLAYER
//  |. . . . I . . . . .|    STYXCEL
//  |. . . . . . . . . .|
//  |I J J J . T T T S S|      LINES
//  |I J O O . L T S S T|          0
//  |I L O O . L Z Z T T|      SCORE
//  |I L L L . L L Z Z T|      00021

#include <bits/stdc++.h>

using namespace std;
// #pragma GCC optimize ("O2,unroll-loops")
// #pragma GCC target ("tune=native")

#define ll long long
#define ull unsigned long long
#define ld long double
#define vi vector<ll>
#define vii vector<vector<ll>>
#define fr() front()
#define bc() back()
#define pushb push_back
#define popb pop_backtop

#define pii pair<ll, ll>
#define piii pair<pair<ll, ll>, ll>
#define fi first
#define se second
#define ff fi.fi
#define fs fi.se
#define sf se.fi
#define ss se.se
#define psplit(pp, a, b) (a = pp.fi, b = pp.se);
#define ppsplit(ppp, a, b, c) (a = ppp.fi.fi, b = ppp.fi.se, c = ppp.se);

#define endl ("\n")
const ll INF = 1 << 30;
const ll LINF = 1 << 62;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;

int main() {

  // freopen("inp.txt","r",stdin);
  // freopen("out.txt","w",stdout);
  // ios::sync_with_stdio(false);
  // cin.tie(0);
  // cout.tie(0);

  int n = 0, m = 0;
  string s;

  cin >> n >> m;
  cin >> s;
  int ye = 0;
  stack<int> jumps;
  int cur = n;
  while (cur > 0) {
    ye = 0;
    for (int i = m; i > 0; i--) {
      if (cur - i >= 0 && s[cur - i] == '0') {
        jumps.push(i);
        cur -= i;
        ye = 1;
        break;
      }
    }
    if (!ye) {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << jumps.top();
  jumps.pop();
  while (!jumps.empty()) {
    cout << " " << jumps.top();
    jumps.pop();
  }
  cout << endl;
  return 0;
}