Language: C++

#include<iostream>
#include<algorithm>
#include<vector>
#include<string>

using namespace std;

int main() {
	int N, K;
	string S;
	vector<int> ar, ruisekiwa;
	cin >> N >> K >> S;
	int cnt = 1;
	char bef = S[0];
	for (int i = 1; i < N; i++) {
		if (S[i] == bef)cnt++;
		else ar.push_back(cnt), cnt = 1, bef = S[i];
	}
	ar.push_back(cnt);

	//calc_ruisekiwa
	ruisekiwa.resize(ar.size() + 1);
	int ans = 0;
	if (S[0] != S.back()) {

		if (S[0] == '0')reverse(ar.begin(), ar.end());
		ruisekiwa[0] = 0;
		for (int i = 1; i < ruisekiwa.size(); i++) {
			ruisekiwa[i] = ruisekiwa[i - 1] + ar[i - 1];
		}

		ans = (ruisekiwa[ar.size()] - ruisekiwa[max(ar.size() - 2 * K, 0U)]);
		for (int i = 0; 2 * K + 1 + i <= ar.size() ; i += 2) {
			ans = max(ans, ruisekiwa[2 * K + 1 + i] - ruisekiwa[i]);
		}
		
	}
	else {

		ruisekiwa[0] = 0;
		for (int i = 1; i < ruisekiwa.size(); i++) {
			ruisekiwa[i] = ruisekiwa[i - 1] + ar[i - 1];
		}

		if (S[0] == '0') {
			ans = max(ruisekiwa[min(2U * K, ar.size())] - ruisekiwa[0], 
				ruisekiwa[ar.size()] - ruisekiwa[max(ar.size() - 2 * K, 0U)]);
			for (int i = 0; i + 2 * K + 2 <= ar.size(); i += 2) {
				ans = max(ans, ruisekiwa[i + 2 * K + 2] - ruisekiwa[i + 1]);
			}
		}
		else {
			if (2 * K + 1 >= ar.size()) {
				ans = ruisekiwa[ar.size()] - ruisekiwa[0];
			}
			else {
				for (int i = 0; 2 * K + 1 + i <= ar.size(); i += 2) {
					ans = max(ans, ruisekiwa[2 * K + 1 + i] - ruisekiwa[i]);
				}
			}

		}
	}
	cout << ans << endl;
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:32:60: error: no matching function for call to 'max(std::vector<int>::size_type, unsigned int)'
   32 |                 ans = (ruisekiwa[ar.size()] - ruisekiwa[max(ar.size() - 2 * K, 0U)]);
      |                                                         ~~~^~~~~~~~~~~~~~~~~~~~~~~
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: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:32:60: note:   deduced conflicting types for parameter 'const _Tp' ('long unsigned int' and 'unsigned int')
   32 |                 ans = (ruisekiwa[ar.size()] - ruisekiwa[max(ar.size() - 2 * K, 0U)]);
      |                                                         ~~~^~~~~~~~~~~~~~~~~~~~~~~
/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:2:
/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:32:60: note:   mismatched types 'std::initializer_list<_Tp>' and 'long unsigned int'
   32 |                 ans = (ruisekiwa[ar.size()] - ruisekiwa[max(ar.size() - 2 * K, 0U)]);
      |                                                         ~~~^~~~~~~~~~~~~~~~~~~~~~~
a.cc:46:48: error: no matching function for call to 'min(unsigned int, std::vector<int>::size_type)'
   46 |                         ans = max(ruisekiwa[min(2U * K, ar.size())] - ruisekiwa[0],
      |                                             ~~~^~~~~~~~~~~~~~~~~~~
/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:46:48: note:   deduced conflicting types for parameter 'const _Tp' ('unsigned int' and 'std::vector<int>::size_type' {aka 'long unsigned int'})
   46 |                         ans = max(ruisekiwa[min(2U * K, ar.size())] - ruisekiwa[0],
      |                                             ~~~^~~~~~~~~~~~~~~~~~~
/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
/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:46:48: note:   mismatched types 'std::initializer_list<_Tp>' and 'unsigned int'
   46 |                         ans = max(ruisekiwa[min(2U * K, ar.size())] - ruisekiwa[0],
      |                                             ~~~^~~~~~~~~~~~~~~~~~~
a.cc:47:69: error: no matching function for call to 'max(std::vector<int>::size_type, unsigned int)'
   47 |                                 ruisekiwa[ar.size()] - ruisekiwa[max(ar.size() - 2 * K, 0U)]);
      |                                                                  ~~~^~~~~~~~~~~~~~~~~~~~~~~
/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:47:69: note:   deduced conflicting types for parameter 'const _Tp' ('long unsigned int' and 'unsigned int')
   47 |                                 ruisekiwa[ar.size()] - ruisekiwa[max(ar.size() - 2 * K, 0U)]);
      |                                                                  ~~~^~~~~~~~~~~~~~~~~~~~~~~
/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
/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:47:69: note:   mismatched types 'std::initializer_list<_Tp>' and 'long unsigned int'
   47 |                                 ruisekiwa[ar.size()] - ruisekiwa[max(ar.size() - 2 * K, 0U)]);
      |                                                                  ~~~^~~~~~~~~~~~~~~~~~~~~~~