Language: C++

#include <bits/stdc++.h>

using namespace std;

char sw_state(char state){
  if(state == '1'){
    return '0';
  }
  else {
    return '1';
  }
}

int main(){
  
  int N,K;
  cin >> N >> K;
  string S;
  cin >> S;

  char state = '1';
  
  vector<int> v;
  /* 最初が0から始まる場合は、１が0個という意味で、0を入れておく */
  
  int count = 0;
  for(int i = 0;i<N;i++){
    if(S[i] == state){
      count++;
    }
    else{
      state = sw_state(state);
      v.push_back(count);
      count = 1;
    }
  }

  if(count == 1){
    v.push_back(count);
  }

  if(S[(N-1)] == '0'){
    v.push_back(0);
  }

  /*
  for(int i=0;i<v.size();i++){
    cout << v[i] << endl;
  }
  */

  vector<int> csum(v.size() + 1); //0から始める
  for(int i=0;i<v.size();i++){
      csum[i+1] == csum[i] + v[i];
  }

  /*
  for(int i=0;i<v.size();i++){
    cout << csum[i] << endl;
  }
  */
  
  int result = 0;
  for(int i=0;i<v.size();i+=2){
    int left = i;
    int right = min(i+2*K,v.size());
    if(i==0){
      result = max(result,(csum[right]));
    }
    else{
      result = max(result,(csum[right]- csum[left]));
    }
  }

  cout << result << endl;
  return 0;

}
  
  
  


Compiler output:
a.cc: In function 'int main()':
a.cc:66:20: error: no matching function for call to 'min(int, std::vector<int>::size_type)'
   66 |     int right = min(i+2*K,v.size());
      |                 ~~~^~~~~~~~~~~~~~~~
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:66:20: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'std::vector<int>::size_type' {aka 'long unsigned int'})
   66 |     int right = min(i+2*K,v.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
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:66:20: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   66 |     int right = min(i+2*K,v.size());
      |                 ~~~^~~~~~~~~~~~~~~~