Language: C++

#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;

int main(void){
  int number, manipulate_number;
  cin >> number >> manipulate_number;

  string s;
  cin >> s;

  vector<int> nums;
  int now = 1;
  int cnt = 0;
  for(int i = 0; i < number; i++){
    if(s[i] == (char)('0' + now)) cnt++;
    else{
      nums.emplace_back(cnt);
      now ^= 1;
      cnt = 1;
    }
  }
  if(cnt != 0) nums.emplace_back(cnt);

  if(nums.size() % 2 == 0) nums.emplace_back(0);


  int add_range = 2 * manipulate_number + 1;
  int ans = 0;

  int tmp = 0;
  for(int i = 0; i < nums.size(); i += 2){
    int next_left = i;
    int next_right = min(i + add_range, (int)nums.size());
    while(next_left > left){
      tmp -= nums[left];
      left++;
    }

    while(next_right > right){
      tmp += nums[right];
      right++;
    }
    ans = max(ans, tmp);
  }
  cout << ans << endl;
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:37:21: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
   37 |     while(next_left > left){
      |           ~~~~~~~~~~^~~~~~
a.cc:38:19: error: invalid conversion from 'std::ios_base& (*)(std::ios_base&)' to 'std::vector<int>::size_type' {aka 'long unsigned int'} [-fpermissive]
   38 |       tmp -= nums[left];
      |                   ^~~~
      |                   |
      |                   std::ios_base& (*)(std::ios_base&)
In file included from /usr/include/c++/14/vector:66,
                 from a.cc:2:
/usr/include/c++/14/bits/stl_vector.h:1128:28: note:   initializing argument 1 of 'std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::operator[](size_type) [with _Tp = int; _Alloc = std::allocator<int>; reference = int&; size_type = long unsigned int]'
 1128 |       operator[](size_type __n) _GLIBCXX_NOEXCEPT
      |                  ~~~~~~~~~~^~~
a.cc:39:7: warning: ISO C++ forbids incrementing a pointer of type 'std::ios_base& (*)(std::ios_base&)' [-Wpointer-arith]
   39 |       left++;
      |       ^~~~
a.cc:39:11: error: lvalue required as increment operand
   39 |       left++;
      |           ^~
a.cc:42:22: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
   42 |     while(next_right > right){
      |           ~~~~~~~~~~~^~~~~~~
a.cc:43:19: error: invalid conversion from 'std::ios_base& (*)(std::ios_base&)' to 'std::vector<int>::size_type' {aka 'long unsigned int'} [-fpermissive]
   43 |       tmp += nums[right];
      |                   ^~~~~
      |                   |
      |                   std::ios_base& (*)(std::ios_base&)
/usr/include/c++/14/bits/stl_vector.h:1128:28: note:   initializing argument 1 of 'std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::operator[](size_type) [with _Tp = int; _Alloc = std::allocator<int>; reference = int&; size_type = long unsigned int]'
 1128 |       operator[](size_type __n) _GLIBCXX_NOEXCEPT
      |                  ~~~~~~~~~~^~~
a.cc:44:7: warning: ISO C++ forbids incrementing a pointer of type 'std::ios_base& (*)(std::ios_base&)' [-Wpointer-arith]
   44 |       right++;
      |       ^~~~~
a.cc:44:12: error: lvalue required as increment operand
   44 |       right++;
      |            ^~