Language: C++

#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

using namespace std;

using llong = long long;
using ullong = unsigned long long;

#ifndef __MACRO_H__
#define __MACRO_H__

#define all(collection)  (collection).begin(), (collection).end()
#define loop(i, times) for (llong i = 0; i < times; i++)
#define rloop(i, times) for (llong i = times -1; 0 <= i; i--)

std::chrono::system_clock::time_point  start;

void TimeStart(void)
{
	start = std::chrono::system_clock::now();
}

void TimeEnd(void)
{
	auto time = std::chrono::system_clock::now() - start;
	auto msec = std::chrono::duration_cast<std::chrono::milliseconds>(time).count();
	cerr << endl << msec << " msec " << endl;
}

#endif

#pragma once

#include "Macro.h"

class ABC124D
{
public:
	ABC124D()
	{
		cin >> n_;
		cin >> k_;
		cin >> s_;
		ans_ = 0;
	}
	void Run(void)
	{
		CreateBlock();

		if (s_[0] == '0' && ceil((llong)block_.size() / 2) <= k_)
		{
			cout << s_.size();
			return;
		}
		else if (s_[0] == '1' && (llong)block_.size() / 2 <= k_)
		{
			cout << s_.size();
			return;
		}

		if (s_[0] == '0')
		{
			loop(i, k_ * 2)
				ans_ += block_[i];
		}

		llong index = 0;
		llong union_block = 0;
		if (index + k_ * 2 + 1 < (llong)block_.size())
		{
			FirstUnionBlock(union_block, index);
			ans_ = max(ans_, union_block);
		}
		while(index + k_ * 2 + 1 < (llong)block_.size())
		{
			NextUnionBlock(union_block, index);
			ans_ = max(ans_, union_block);
		}
		LastUnionBlock(union_block, index);
		ans_ = max(ans_, union_block);

		cout << ans_;
	}
private:
	void FirstUnionBlock(llong& union_block, llong& index)
	{
		if (s_[0] == '0')
		{
			for(llong i = 1; i < k_ * 2 + 1; i++)
				union_block += block_[i];
			index = 3;
		}
		else
		{
			for(llong i = 0; i < k_ * 2 + 1; i++)
				union_block += block_[i];
			index = 4;
		}
	}
	void NextUnionBlock(llong& union_block, llong& index)
	{
		union_block = union_block - block_[index] - block_[index+1] + block_[index + k_ * 2] + block_[index + k_ * 2 + 1];
		index += 2;
	}
	void LastUnionBlock(llong& union_block, llong& index)
	{
		union_block = 0;
		while (index < (llong)block_.size())
		{
			union_block += block_[index];
			index++;
		}
	}
	void CreateBlock(void)
	{
		llong s_index = 0;
		while(s_index < (llong)s_.size())
		{
			block_.push_back(BlockEnd(s_index) - s_index + 1);
			s_index += block_[(llong)block_.size()-1];
		}
	}
	llong BlockEnd(llong start_index)
	{
		llong end_index = start_index;

		while (s_[start_index] == s_[start_index + 1])
		{
			end_index++;
			start_index++;
		}

		return end_index;
	}

	llong n_;
	llong k_;
	string s_;
	vector<llong> block_;
	llong ans_;
};

int main(void)
{
	ABC124D abc124d;
	abc124d.Run();

	return 0;
}


Compiler output:
a.cc:103:9: warning: #pragma once in main file
  103 | #pragma once
      |         ^~~~
a.cc:105:10: fatal error: Macro.h: No such file or directory
  105 | #include "Macro.h"
      |          ^~~~~~~~~
compilation terminated.