Language: C++

#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include <cmath>
#include <limits>
#include <utility>
#include <map>
#include <iomanip>




#define rep(p,q) for(int i = p;i < q;i++)
#define ll long long

using namespace std;

const int cons = 1e9 + 7;

//D

int main(void) {
	string s;
	int n,k;
	cin >> n >> k >> s;
	char nextChr = s[0];
	int count0 = 0, count1 = 0;
	vector<int> ruiseki0 = vector<int>();
	vector<int> ruiseki1 = vector<int>();
	ruiseki0.push_back(0);
	ruiseki1.push_back(0);
	char formerChr = nextChr;
	if (formerChr == '0')count0++; else count1++;
	bool FirstIsNormal = formerChr == '0';
	if (formerChr == '0')FirstIsNormal = false; else FirstIsNormal = true;
	rep(0, n) {
		if(i < n)nextChr = s[i + 1];
		else nextChr = formerChr;
		if (formerChr == nextChr) {
			if (formerChr == '0')count0++; else count1++;	
		}
		else {
			if (count0 == 0 && count1 == 0) {
				if (formerChr == '0')count0++; else count1++;
			}
			if (formerChr == '0') {
					int last = ruiseki0[ruiseki0.size() - 1];
					ruiseki0.push_back(count0 + last);
				
				count0 = 0;
			}
			else {
					int last = ruiseki1[ruiseki1.size() - 1];
					ruiseki1.push_back(count1 + last);
				
				count1 = 0;
			}
		}
		formerChr = nextChr;
	}
	if (count0 != 0) {
			int last = ruiseki0[ruiseki0.size() - 1];
			ruiseki0.push_back(count0 + last);
		
	}
	if (count1 != 0) {
			int last = ruiseki1[ruiseki1.size() - 1];
			ruiseki1.push_back(count1 + last);
		
	}

	int ans = 0;
	if (ruiseki0.size() < k) {
		cout << n << endl;
	}
	else {	
		if (FirstIsNormal) {
			for (int i = 0; i + k < ruiseki0.size(); i++) {
				int r1Index = min((unsigned)i + k, ruiseki1.size() - 1);
				ans = max(ans, ruiseki0[i + k ] - ruiseki0[i] + ruiseki1[r1Index] - ruiseki1[min(r1Index - k, 0)]);
			}
		}
		else
		{
			for (int i = 0; i + k< ruiseki0.size(); i++) {
				int r1Index = min((unsigned)i + k, ruiseki1.size() - 1);
				ans = max(ans, ruiseki0[i + k ] - ruiseki0[i] + ruiseki1[r1Index] - ruiseki1[min(r1Index - k,0)]);
			}
		}
	}
	cout << ans << endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:80:50: error: no matching function for call to 'min(unsigned int, std::vector<int>::size_type)'
   80 |                                 int r1Index = min((unsigned)i + k, ruiseki1.size() - 1);
      |                                               ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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: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:80:50: note:   deduced conflicting types for parameter 'const _Tp' ('unsigned int' and 'std::vector<int>::size_type' {aka 'long unsigned int'})
   80 |                                 int r1Index = min((unsigned)i + k, ruiseki1.size() - 1);
      |                                               ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/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,
                 from a.cc:3:
/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:80:50: note:   mismatched types 'std::initializer_list<_Tp>' and 'unsigned int'
   80 |                                 int r1Index = min((unsigned)i + k, ruiseki1.size() - 1);
      |                                               ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:87:50: error: no matching function for call to 'min(unsigned int, std::vector<int>::size_type)'
   87 |                                 int r1Index = min((unsigned)i + k, ruiseki1.size() - 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:87:50: note:   deduced conflicting types for parameter 'const _Tp' ('unsigned int' and 'std::vector<int>::size_type' {aka 'long unsigned int'})
   87 |                                 int r1Index = min((unsigned)i + k, ruiseki1.size() - 1);
      |                                               ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/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:87:50: note:   mismatched types 'std::initializer_list<_Tp>' and 'unsigned int'
   87 |                                 int r1Index = min((unsigned)i + k, ruiseki1.size() - 1);
      |                                               ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~