Language: C++

// In the name of God

#include <bits/stdc++.h>

using namespace std;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	int n, k;
	cin >> n >> k;
	string s;
	cin >> s;

	int len = 1;
	vector<int> comps;
	vector<bool> tp;
	for(int i = 1; i < n; i++) {
		if(s[i] != s[i-1]) {
			tp.push_back( (s[i]-'0') ^ 1 );
			comps.push_back(len);
			len = 1;
		}
		else len++;
	}

	comps.push_back(len);
	tp.push_back((s[(int)s.length()-1]-'0'));

	if(comps.size()==1) {
		cout << comps[0];
		exit(0);
	}

	int ans = 0;

	int go = 0;
	int ptr = 0;
	int sum = 0;

	for(int i = 0; i < comps.size(); i++) {
		if(tp[i]==0) go++;
		sum += comps[i];
		while(go>k) {
			if(tp[ptr]==0) go--;
			sum -= comps[ptr];
			ptr++;
		}
		if(tp[i]) {
			ans=max(ans, sum);
		}
	}

	for(int i = 0; i < tp.size(); i++) tp[i] ^= 1;

	go = 0;
	ptr = 0;
	sum = 0;
	
	k--;

	for(int i = 0; i < comps.size(); i++) {
		if(tp[i]==0) go++;
		sum += comps[i];
		while(go>k) {
			if(tp[ptr]==0) go--;
			sum -= comps[ptr];
			ptr++;
		}
		if(tp[i]) {
			ans=max(ans, sum);
		}
	}

	cout << ans;

	return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:55:50: error: no match for 'operator^=' (operand types are 'std::vector<bool>::reference' and 'int')
   55 |         for(int i = 0; i < tp.size(); i++) tp[i] ^= 1;
      |                                            ~~~~~~^~~~
In file included from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:41,
                 from a.cc:3:
/usr/include/c++/14/cstddef:178:3: note: candidate: 'constexpr std::byte& std::operator^=(byte&, byte)'
  178 |   operator^=(byte& __l, byte __r) noexcept
      |   ^~~~~~~~
/usr/include/c++/14/cstddef:178:20: note:   no known conversion for argument 1 from 'std::vector<bool>::reference' to 'std::byte&'
  178 |   operator^=(byte& __l, byte __r) noexcept
      |              ~~~~~~^~~
In file included from /usr/include/c++/14/streambuf:43,
                 from /usr/include/c++/14/bits/streambuf_iterator.h:35,
                 from /usr/include/c++/14/iterator:66,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:54:
/usr/include/c++/14/bits/ios_base.h:114:3: note: candidate: 'constexpr const std::_Ios_Fmtflags& std::operator^=(_Ios_Fmtflags&, _Ios_Fmtflags)'
  114 |   operator^=(_Ios_Fmtflags& __a, _Ios_Fmtflags __b) _GLIBCXX_NOTHROW
      |   ^~~~~~~~
/usr/include/c++/14/bits/ios_base.h:114:29: note:   no known conversion for argument 1 from 'std::vector<bool>::reference' to 'std::_Ios_Fmtflags&'
  114 |   operator^=(_Ios_Fmtflags& __a, _Ios_Fmtflags __b) _GLIBCXX_NOTHROW
      |              ~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/ios_base.h:164:3: note: candidate: 'constexpr const std::_Ios_Openmode& std::operator^=(_Ios_Openmode&, _Ios_Openmode)'
  164 |   operator^=(_Ios_Openmode& __a, _Ios_Openmode __b) _GLIBCXX_NOTHROW
      |   ^~~~~~~~
/usr/include/c++/14/bits/ios_base.h:164:29: note:   no known conversion for argument 1 from 'std::vector<bool>::reference' to 'std::_Ios_Openmode&'
  164 |   operator^=(_Ios_Openmode& __a, _Ios_Openmode __b) _GLIBCXX_NOTHROW
      |              ~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/ios_base.h:211:3: note: candidate: 'constexpr const std::_Ios_Iostate& std::operator^=(_Ios_Iostate&, _Ios_Iostate)'
  211 |   operator^=(_Ios_Iostate& __a, _Ios_Iostate __b) _GLIBCXX_NOTHROW
      |   ^~~~~~~~
/usr/include/c++/14/bits/ios_base.h:211:28: note:   no known conversion for argument 1 from 'std::vector<bool>::reference' to 'std::_Ios_Iostate&'
  211 |   operator^=(_Ios_Iostate& __a, _Ios_Iostate __b) _GLIBCXX_NOTHROW
      |              ~~~~~~~~~~~~~~^~~
In file included from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:176:
/usr/include/c++/14/future:189:18: note: candidate: 'constexpr std::launch& std::operator^=(launch&, launch)'
  189 |   inline launch& operator^=(launch& __x, launch __y) noexcept
      |                  ^~~~~~~~
/usr/include/c++/14/future:189:37: note:   no known conversion for argument 1 from 'std::vector<bool>::reference' to 'std::launch&'
  189 |   inline launch& operator^=(launch& __x, launch __y) noexcept
      |                             ~~~~~~~~^~~
In file included from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:198:
/usr/include/c++/14/charconv:654:3: note: candidate: 'constexpr std::chars_format& std::operator^=(chars_format&, chars_format)'
  654 |   operator^=(chars_format& __lhs, chars_format __rhs) noexcept
      |   ^~~~~~~~
/usr/include/c++/14/charconv:654:28: note:   no known conversion for argument 1 from 'std::vector<bool>::reference' to 'std::chars_format&'
  654 |   operator^=(chars_format& __lhs, chars_format __rhs) noexcept
      |              ~~~~~~~~~~~~~~^~~~~