Language: C++

#include <iostream>
#include <string>
#include <vector>
#include <cmath>

int main()
{
  int N, K;
  std::cin >> N >> K;
  std::string S;
  std::cin >> S;
  std::vector<bool> is_stands;
  std::vector<int> run;

  // run length encoding
  if(S[0] == '0')
    {
      is_stands.push_back(false);
    }
  else
    {
      is_stands.push_back(true);
    }
  run.push_back(1);

  for(size_t i = 1;
      i < S.length();
      ++i)
    {
      if(S[i] != S[i - 1])
        {
          if(S[i] == '0')
            {
              is_stands.push_back(false);
            }
          else
            {
              is_stands.push_back(true);
            }
          run.push_back(1);
        }
      else
        {
          ++run.back();
        }
    }

  // total #zeros
  int total_num_zero;
  if(!is_stands[0])
    {
      total_num_zero = ceil(static_cast<double>(is_stands.size())/2);
    }
  else
    {
      total_num_zero = floor(static_cast<double>(is_stands.size())/2);
    }

  if(total_num_zero <= K)
    {
      std::cout << S.length() << std::endl;
      return 1;
    }


  int spos = 0;
  int lpos = (K << 1);
  int ret = 0;
  int sum = 0;

  if(!is_stands[spos])
    {
      for(size_t i = 0;
          i < std::min(lpos,is_stands.size());
          ++i)
        {
          sum += run[i];
        }
    }
  else
    {
      for(size_t i = 0;
          i <= std::min(lpos,is_stands.size() - 1);
          ++i)
        {
          sum += run[i];
        }
      ++lpos;
    }
  ++spos;
  ret = sum;
  for(;
      spos < is_stands.size() - 2*K + 1;
      ++spos,
      ++lpos)
    {
      sum -= run[spos - 1];
      if(lpos < is_stands.size())
        {
          sum += run[lpos];
        }
      if(is_stands[spos])
        {
          ret = std::max(ret,sum);
        }
    }

  std::cout << ret << std::endl;

  return 1;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:74:23: error: no matching function for call to 'min(int&, std::vector<bool>::size_type)'
   74 |           i < std::min(lpos,is_stands.size());
      |               ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/string:51,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 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:74:23: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'std::vector<bool>::size_type' {aka 'long unsigned int'})
   74 |           i < std::min(lpos,is_stands.size());
      |               ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
/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
a.cc:83:24: error: no matching function for call to 'min(int&, std::vector<bool>::size_type)'
   83 |           i <= std::min(lpos,is_stands.size() - 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:83:24: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'std::vector<bool>::size_type' {aka 'long unsigned int'})
   83 |           i <= std::min(lpos,is_stands.size() - 1);
      |                ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
/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