Language: C++

// All Library
// #include <bits/stdc++.h> // https://github.com/gcc-mirror/gcc/blob/master/libstdc%2B%2B-v3/include/precompiled/stdc%2B%2B.h

// C Library
// #include <cassert> // (assert.h) C Diagnostics Library (header)
// #include <cctype> // (ctype.h) Character handling functions (header)
// #include <cerrno> // (errno.h) C Errors (header)
// #include <cfloat> // (float.h) Characteristics of floating-point types (header)
// #include <ciso646> // (iso646.h) ISO 646 Alternative operator spellings (header)
#include <climits> // (limits.h) Sizes of integral types (header)
// #include <clocale> // (locale.h) C localization library (header)
#include <cmath> // (math.h) C numerics library (header)
// #include <csetjmp> // (setjmp.h) Non local jumps (header)
// #include <csignal> // (signal.h) C library to handle signals (header)
// #include <cstdarg> // (stdarg.h) Variable arguments handling (header)
// #include <cstdbool> // (stdbool.h) Boolean type (header)
// #include <cstddef> // (stddef.h) C Standard definitions (header)
// #include <cstdint> // (stdint.h) Integer types (header)
#include <cstdio> // (stdio.h) C library to perform Input/Output operations (header)
// #include <cstdlib> // (stdlib.h) C Standard General Utilities Library (header)
// #include <cstring> // (string.h) C Strings (header)
// #include <ctime> // (time.h) C Time Library (header)
// #include <cuchar> // (uchar.h) Unicode characters (header)
// #include <cwchar> // (wchar.h) Wide characters (header)
// #include <cwctype> // (wctype.h) Wide character type (header)

// Containers
// #include <array> // Array header (header)
// #include <bitset> // Bitset header (header)
#include <deque> // Deque header (header)
// #include <forward_list> // Forward list (header)
// #include <list> // List header (header)
#include <map> // Map header (header)
// #include <queue> // Queue header (header)
#include <set> // Set header (header)
// #include <stack> // Stack header (header)
// #include <unordered_map> //Unordered map header (header)
// #include <unordered_set> // Unordered set header (header)
#include <vector> // Vector header (header)

// Input/Output Stream Library
#include <iostream> // The class relies on a single streambuf object for both the input and output operations.
// #include <fstream> // Input/output stream class to operate on files.
// #include <sstream> //

// Miscellaneous headers
#include <algorithm> // Standard Template Library: Algorithms (library )
// #include <chrono> // Time library (header)
// #include <codecvt> // Unicode conversion facets (header)
// #include <complex> // Complex numbers library (header)
// #include <exception> // Standard exceptions (header)
// #include <functional> // Function objects (header)
// #include <initializer_list> // Initializer list (header)
// #include <iterator> // Iterator definitions (header)
// #include <limits> // Numeric limits (header)
// #include <locale> // Localization library (header)
// #include <memory> //Memory elements (header)
// #include <new> // Dynamic memory (header)
// #include <numeric> // Generalized numeric operations (header)
// #include <random> // Random (header)
// #include <ratio> // Ratio header (header)
// #include <regex> // Regular Expressions (header)
// #include <stdexcept> // Exception classes (header)
#include <string> // Strings (header)
// #include <system_error> // System errors (header)
#include <tuple> // Tuple library (header)
// #include <typeinfo> // Type information (header)
// #include <type_traits> //type_traits (header)
// #include <utility> // Utility components (header)
// #include <valarray> // Library for arrays of numeric values (header)

// Boost
// #include <boost/multiprecision/cpp_int.hpp> // https://boostjp.github.io/tips/multiprec-int.html

// policy-based data structure
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>

using namespace std;
// using namespace boost::multiprecision;
// using namespace __gnu_pbds;

#define BEGIN ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define END return EXIT_SUCCESS
#define rep(I,N) for(auto I=0;I<(N);++I)
#define up(I,A,B) for(auto I=(A);I<=(B);++I)
#define dw(I,A,B) for(auto I=(A);I>=(B);--I)
#define all(C) (C).begin(),(C).end()
#define rall(C) (C).rbegin(),(C).rend()
#define ft first
#define sd second
#define mp make_pair
#define mt make_tuple
#define pf push_front
#define pb push_back
#define pt pop_front
#define pk pop_back
#define lb lower_bound
#define ub upper_bound
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
template<class T>inline void                             in(T &p){cin>>p;}
template<class T1,class T2>inline void                   in(T1 &p1,T2 &p2){cin>>p1>>p2;}
template<class T1,class T2,class T3>inline void          in(T1 &p1,T2 &p2,T3 &p3){cin>>p1>>p2>>p3;}
template<class T1,class T2,class T3,class T4>inline void in(T1 &p1,T2 &p2,T3 &p3,T4 &p4){cin>>p1>>p2>>p3>>p4;}
template<class T>inline void                             ins(T &p){for_each(all(p),in<decltype(p[0])>);}
template<class T>inline void                             out(T p){cout<<p<<endl;}
template<class T1,class T2>inline void                   out(T1 p1,T2 p2){cout<<p1<<" "<<p2<<endl;}
template<class T1,class T2,class T3>inline void          out(T1 p1,T2 p2,T3 p3){cout<<p1<<" "<<p2<<" "<<p3<<endl;}
template<class T1,class T2,class T3,class T4>inline void out(T1 p1,T2 p2,T3 p3,T4 p4){cout<<p1<<" "<<p2<<" "<<p3<<" "<<p4<<endl;}
template<class T>inline void                             outs(T p){for_each(all(p),out<decltype(p[0])>);}

inline void solve(void){
  long N,K;
  string S;
  in(N,K,S);
  long cnt=1;
  vector<long>v;
  for(long i=1;i<N;i++){
    if(S[i]==S[i-1])cnt++;
    else{
      v.pb(cnt);
      cnt=1;
    }
  }
  v.pb(cnt);
  long M=v.size();
  vector<long>s(M+1);
  for(int i=0;i<M;i++){
    s[i+1]=s[i]+v[i];
  }
  long ans=1;
  long L=2*K+1,A;
  if(S[0]=='1')A=0;
  else A=1;
  for(long i=A;i+L<=M;i+=2){
    chmax(ans, s[i+L]-s[i]);
  }
  if(S[0]=='0'){
    chmax(ans,s[min(K*2,M)]-s[0]);
  }
  if(S[N-1]=='0'){
    chmax(ans,s[M]-s[max(M-K*2,0)]);
  }
  out(ans);
}

int main(int argc,char**argv){
  BEGIN;
  solve();
  END;
}


Compiler output:
a.cc: In function 'void solve()':
a.cc:143:25: error: no matching function for call to 'max(long int, int)'
  143 |     chmax(ans,s[M]-s[max(M-K*2,0)]);
      |                      ~~~^~~~~~~~~
In file included from /usr/include/c++/14/bits/specfun.h:43,
                 from /usr/include/c++/14/cmath:3906,
                 from a.cc:12:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:143:25: note:   deduced conflicting types for parameter 'const _Tp' ('long int' and 'int')
  143 |     chmax(ans,s[M]-s[max(M-K*2,0)]);
      |                      ~~~^~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61,
                 from a.cc:47:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:143:25: note:   mismatched types 'std::initializer_list<_Tp>' and 'long int'
  143 |     chmax(ans,s[M]-s[max(M-K*2,0)]);
      |                      ~~~^~~~~~~~~