Language: C++

#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define mk make_pair
#define fi first
#define se second
#define vll vector<ll>
#define pii pair<ll,ll>
#define vvll vector< vector<ll> >
#define pb push_back
#define inf 1e16
#define M 1000000007
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
#define mx 1000010

int main(){
	IOS;
	ll n,k;cin>>n>>k;
	string s;cin>>s;
	vll v;
	ll c=1;
	rep(i,1,s.length()){
		if(s[i]==s[i-1])c++;
		else v.pb(c),c=1;
	}v.pb(c);
	ll sum=0,ans=-1,f=0;
	if(s[0]=='0'){
		rep(i,0,min(2*k,v.size()))sum+=v[i];
		ans=max(ans,sum);
		rep(i,0,v.size()){
			if(i%2==0){
				sum-=v[i];
				if(i>=1)sum-=v[i-1];
				if(i+2*k<=v.size()-1)sum+=v[i+2*k];
				else break;
				if(i+2*k+1<=v.size()-1)sum+=v[i+2*k+1];
				else break;
				ans=max(ans,sum);
			}
		}
	}
	else{
		rep(i,0,min(v.size(),2*k+1))sum+=v[i];
		ans=max(ans,sum);
		rep(i,0,v.size()){
			if(i%2==1){
				sum-=v[i];
				if(i>=1)sum-=v[i-1];
				if(i+2*k<=v.size()-1)sum+=v[i+2*k];
				else break;
				if(i+2*k+1<=v.size()-1)sum+=v[i+2*k+1];
				else break;
				ans=max(ans,sum);
			}
		}
	}
	cout<<ans;
	return 0;
}



Compiler output:
a.cc: In function 'int main()':
a.cc:31:28: error: no matching function for call to 'min(long long int, std::vector<long long int>::size_type)'
   31 |                 rep(i,0,min(2*k,v.size()))sum+=v[i];
      |                         ~~~^~~~~~~~~~~~~~
a.cc:14:33: note: in definition of macro 'rep'
   14 | #define rep(i,a,b) for(ll i=a;i<b;++i)
      |                                 ^
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 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:31:28: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'})
   31 |                 rep(i,0,min(2*k,v.size()))sum+=v[i];
      |                         ~~~^~~~~~~~~~~~~~
a.cc:14:33: note: in definition of macro 'rep'
   14 | #define rep(i,a,b) for(ll i=a;i<b;++i)
      |                                 ^
/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:
/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:31:28: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   31 |                 rep(i,0,min(2*k,v.size()))sum+=v[i];
      |                         ~~~^~~~~~~~~~~~~~
a.cc:14:33: note: in definition of macro 'rep'
   14 | #define rep(i,a,b) for(ll i=a;i<b;++i)
      |                                 ^
a.cc:46:28: error: no matching function for call to 'min(std::vector<long long int>::size_type, long long int)'
   46 |                 rep(i,0,min(v.size(),2*k+1))sum+=v[i];
      |                         ~~~^~~~~~~~~~~~~~~~
a.cc:14:33: note: in definition of macro 'rep'
   14 | #define rep(i,a,b) for(ll i=a;i<b;++i)
      |                                 ^
/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:28: note:   deduced conflicting types for parameter 'const _Tp' ('long unsigned int' and 'long long int')
   46 |                 rep(i,0,min(v.size(),2*k+1))sum+=v[i];
      |                         ~~~^~~~~~~~~~~~~~~~
a.cc:14:33: note: in definition of macro 'rep'
   14 | #define rep(i,a,b) for(ll i=a;i<b;++i)
      |                                 ^
/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:28: note:   mismatched types 'std::initializer_list<_Tp>' and 'long unsigned int'
   46 |                 rep(i,0,min(v.size(),2*k+1))sum+=v[i];
      |                         ~~~^~~~~~~~~~~~~~~~
a.cc:14:33: note: in definition of macro 'rep'
   14 | #define rep(i,a,b) for(ll i=a;i<b;++i)
      |                                 ^