Language: C++

#include <bits/stdc++.h>

#include <iostream>
//#include <algorithm>
// #include <iomanip>
#define ll long long
// #define map unordered_map
// #define set unordered_set

using namespace std;

const ll MOD = 1000000007;
const ll INF = (1LL << 62);

int main() {
  ll N, K;
  scanf("%lld %lld", &N, &K);

  string s;
  cin >> s;

  // map<ll, ll> m;

  // ll start1_index = -1;
  // for (ll i = 0; i < s.size(); i++) {
  //   char ch = s[i];

  //   if (ch == '0') {
  //     if (start1_index >= 0) {
  //       m[start1_index] = i - start1_index;
  //       start1_index = -1;
  //     } else {
  //     }
  //   } else {
  //     if (start1_index >= 0) {
  //     } else {
  //       start1_index = i;
  //     }
  //   }
  // }

  // if (!(m.find(0) != m.end())) {
  //   m[-1] = 0;
  // }
  // if (s[s.size() - 1] == '1') {
  //   m[start1_index] = s.size() - start1_index;
  // } else {
  //   m[s.size()] = 0;
  // }

  // auto ite = m.begin();

  // for (; ite != end(m); ite++) {
  //   cout << (*ite).first << "," << (*ite).second << endl;
  // }

  vector<pair<ll, ll>> list;

  if (s[0] == '0') {
    list.emplace_back(make_pair(0, 0));
  }

  ll start1_index = -1;
  for (ll i = 0; i < s.size(); i++) {
    char ch = s[i];

    if (ch == '0') {
      if (start1_index >= 0) {
        ll len = i - start1_index;
        list.emplace_back(make_pair(start1_index, len));
        start1_index = -1;
      } else {
      }
    } else {
      if (start1_index >= 0) {
      } else {
        start1_index = i;
      }
    }
  }

  if (s[s.size() - 1] == '1') {
    ll len = s.size() - start1_index;
    list.emplace_back(make_pair(start1_index, len));
  } else {
    list.emplace_back(make_pair(s.size(), 0));
  }

  // for (ll i = 0; i < list.size(); i++) {
  //   cout << list[i].first << "," << list[i].second << endl;
  // }

  ll ans = 0;

  for (ll i = 0; i < list.size(); i++) {
    ll start_index = list[i].first;

    ll index2 = min(list.size() - 1LL, i + K);

    ll end_index = list[index2].first;

    ll length = (end_index - start_index) + list[index2].second;

    ans = max(ans, length);
  }

  cout << ans << endl;
}

// 11101010110011

// 0,3
// 4,1
// 6,1
// 8,2
// 12,2


Compiler output:
a.cc: In function 'int main()':
a.cc:98:20: error: no matching function for call to 'min(long long unsigned int, long long int)'
   98 |     ll index2 = min(list.size() - 1LL, i + K);
      |                 ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:98:20: note:   deduced conflicting types for parameter 'const _Tp' ('long long unsigned int' and 'long long int')
   98 |     ll index2 = min(list.size() - 1LL, i + K);
      |                 ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   template argument deduction/substitution failed:
a.cc:98:20: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long unsigned int'
   98 |     ll index2 = min(list.size() - 1LL, i + K);
      |                 ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~