Language: C++

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
vector<pair<char, int>> runLengthEncoding(string s) {
	int n = s.length();
 
	vector<pair<char, int>> res;
	char pre = s[0];
	int cnt = 1;
	rep(i, 1, n) {
		if (pre != s[i]) {
			res.push_back({ pre, cnt });
			pre = s[i];
			cnt = 1;
		}
		else cnt++;
	}
 
	res.push_back({ pre, cnt });
	return res;
}
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/
 
 
 
 
 
 
int N, K; string S;
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N >> K >> S;
 
	auto blocks = runLengthEncoding(S);
	int M = blocks.size();
	int ans = 0;
	int sm = 0;
	int L = 0;
	int zero = 0;
	rep(R, 0, M) {
		sm += blocks[R].second;
		if (blocks[R].first == '0') zero++;
 
		while (K < zero) {
			sm -= blocks[L].second;
			if (blocks[L].first == '0') zero--;
			L++;
		}
 
		chmax(ans, sm);
	}
	cout << ans << endl;
}
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
vector<pair<char, int>> runLengthEncoding(string s) {
	int n = s.length();

	vector<pair<char, int>> res;
	char pre = s[0];
	int cnt = 1;
	rep(i, 1, n) {
		if (pre != s[i]) {
			res.push_back({ pre, cnt });
			pre = s[i];
			cnt = 1;
		}
		else cnt++;
	}

	res.push_back({ pre, cnt });
	return res;
}
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/






int N, K; string S;
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N >> K >> S;

	auto blocks = runLengthEncoding(S);
	int M = blocks.size();
	int ans = 0;
	int sm = 0;
	int L = 0;
	int zero = 0;
	rep(R, 0, M) {
		sm += blocks[R].second;
		if (blocks[R].first == '0') zero++;

		while (K < zero) {
			sm -= blocks[L].second;
			if (blocks[L].first == '0') zero--;
			L++;
		}

		chmax(ans, sm);
	}
	cout << ans << endl;
}

Compiler output:
a.cc:76:40: error: redefinition of 'int main()'
   76 | using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
      |                                        ^~~~
a.cc:7:40: note: 'int main()' previously defined here
    7 | using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
      |                                        ^~~~
a.cc:77:33: error: redefinition of 'const int inf'
   77 | typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
      |                                 ^~~
a.cc:8:33: note: 'const int inf' previously defined here
    8 | typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
      |                                 ^~~
a.cc:77:61: error: redefinition of 'const ll infl'
   77 | typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
      |                                                             ^~~~
a.cc:8:61: note: 'const ll infl' previously defined here
    8 | typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
      |                                                             ^~~~
a.cc:78:23: error: redefinition of 'template<class T> bool chmax(T&, const T&)'
   78 | template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
      |                       ^~~~~
a.cc:9:23: note: 'template<class T> bool chmax(T&, const T&)' previously declared here
    9 | template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
      |                       ^~~~~
a.cc:79:23: error: redefinition of 'template<class T> bool chmin(T&, const T&)'
   79 | template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
      |                       ^~~~~
a.cc:10:23: note: 'template<class T> bool chmin(T&, const T&)' previously declared here
   10 | template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
      |                       ^~~~~
a.cc:81:25: error: redefinition of 'std::vector<std::pair<char, int> > runLengthEncoding(std::string)'
   81 | vector<pair<char, int>> runLengthEncoding(string s) {
      |                         ^~~~~~~~~~~~~~~~~
a.cc:12:25: note: 'std::vector<std::pair<char, int> > runLengthEncoding(std::string)' previously defined here
   12 | vector<pair<char, int>> runLengthEncoding(string s) {
      |                         ^~~~~~~~~~~~~~~~~
a.cc:114:5: error: redefinition of 'int N'
  114 | int N, K; string S;
      |     ^
a.cc:45:5: note: 'int N' previously declared here
   45 | int N, K; string S;
      |     ^
a.cc:114:8: error: redefinition of 'int K'
  114 | int N, K; string S;
      |        ^
a.cc:45:8: note: 'int K' previously declared here
   45 | int N, K; string S;
      |        ^
a.cc:114:18: error: redefinition of 'std::string S'
  114 | int N, K; string S;
      |                  ^
a.cc:45:18: note: 'std::string S' previously declared here
   45 | int N, K; string S;
      |                  ^
a.cc:116:6: error: redefinition of 'void _main()'
  116 | void _main() {
      |      ^~~~~
a.cc:47:6: note: 'void _main()' previously defined here
   47 | void _main() {
      |      ^~~~~