Language: C++

#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stdio.h>
#include <stack>
#include <queue>
#include <deque>
#include <numeric>
#include <bits/stdc++.h>
#include <utility>
#include <iomanip>

#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,a,b) for(int i = (a); (b) <= i; i--)
#define REP(i,n) for(int i = 0; i < (n); i++)
#define RREP(i,n) for(int i = n; n <= i; i--)
#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))
#define elif else if
#define MOD 1000000007
#define INF (1<<30)

using namespace std;

#define ld long double
#define ll long long

map <int ,int> mpa,mpb;
typedef pair<ll, ll> P;
priority_queue<P, vector<P>, greater<P>> pque;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  ll N,K;
  cin >> N >> K;
  string S;
  vector <ll> v;
  cin >> S;
  int cnt=0;
  vector<ll> v;
  for(int i=0;i<N;i++){
    if(S[i]=='0'){
      cnt++;
      if(S[i+1]=='1'){
        v.push_back(cnt);
        cnt=0;
      }
    }
    }else{
      cnt++;
      if(S[i+1]=='0'){
        v.push_back(cnt);
        cnt=0;
      }
    }
  }

  ll sum=0;
  ll n=v.size();
  for(int i=0;i<=2*K-1;i++){
      sum+=v[i];
  }
  for(int i=0;i<n-2*K+1;i++){
    sum=sum-v[i]+v[i+2*K-1]
    ans=max(sum,ans);
  }
  sum=0;
  if(S[i]=='1'){
    for(int i=0;i<=2*K-1;i++){
        sum+=v[i];
    }
    ll ous= n/(2*K+1)+(n-2*K-1)/2;
    for(int i=0;i<ous-1;i++){
      sum=sum-v[i*2]-v[2*i+1]+v[2*i+2*K+1]+v[2*i+1+2*K+1];
      ans=max(ans,sum);
    }
  }
  cout << ans << endl;
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:47:14: error: redeclaration of 'std::vector<long long int> v'
   47 |   vector<ll> v;
      |              ^
a.cc:44:15: note: 'std::vector<long long int> v' previously declared here
   44 |   vector <ll> v;
      |               ^
a.cc:56:6: error: 'else' without a previous 'if'
   56 |     }else{
      |      ^~~~
a.cc:58:12: error: 'i' was not declared in this scope
   58 |       if(S[i+1]=='0'){
      |            ^
a.cc: At global scope:
a.cc:66:8: error: 'v' was not declared in this scope
   66 |   ll n=v.size();
      |        ^
a.cc:67:3: error: expected unqualified-id before 'for'
   67 |   for(int i=0;i<=2*K-1;i++){
      |   ^~~
a.cc:67:15: error: 'i' does not name a type
   67 |   for(int i=0;i<=2*K-1;i++){
      |               ^
a.cc:67:24: error: 'i' does not name a type
   67 |   for(int i=0;i<=2*K-1;i++){
      |                        ^
a.cc:70:3: error: expected unqualified-id before 'for'
   70 |   for(int i=0;i<n-2*K+1;i++){
      |   ^~~
a.cc:70:15: error: 'i' does not name a type
   70 |   for(int i=0;i<n-2*K+1;i++){
      |               ^
a.cc:70:25: error: 'i' does not name a type
   70 |   for(int i=0;i<n-2*K+1;i++){
      |                         ^
a.cc:74:3: error: 'sum' does not name a type
   74 |   sum=0;
      |   ^~~
a.cc:75:3: error: expected unqualified-id before 'if'
   75 |   if(S[i]=='1'){
      |   ^~
a.cc:85:3: error: 'cout' does not name a type
   85 |   cout << ans << endl;
      |   ^~~~
a.cc:86:3: error: expected unqualified-id before 'return'
   86 |   return 0;
      |   ^~~~~~
a.cc:87:1: error: expected declaration before '}' token
   87 | }
      | ^