Language: C++

#include <bits/stdc++.h>
using namespace std;

int main() {
    long n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    vector<long> zeros;
    vector<long> ones;
    bool state;
    if (s[0] == '0') state = 0;
    else state = 1;
    long counts = 1;
    for (long i=1; i<n; i++) {
        if (s[i]=='1' && !state) {
            zeros.push_back(counts);
            counts = 1;
            state = !state;
            continue;
        }
        if (s[i]=='0' && state) {
            ones.push_back(counts);
            counts = 1;
            state = !state;
            continue;
        }
        counts++;
    }
    if (state) ones.push_back(counts);
    else zeros.push_back(counts);
    vector<long> sum1(ones.size()), sum0(zeros.size());
    partial_sum(ones.begin(),ones.end(),sum1.begin());
    partial_sum(zeros.begin(),zeros.end(),sum0.begin());
    if (k>=zeros.size()) {
        cout << n;
        return 0;
    }
    bool bottom = 0;
	long res = 0;
    if (zeros.size()>ones.size()) bottom = 1;
    for (long i=0; i<zeros.size()-k+1; i++) {
        if (zeros.size()==ones.size()) res = max(res,sum0[i+k-1]-sum0[i]+zeros[i]+sum1[i+k-1]-sum1[i]+ones[i]);
		else {
			if (bottom) {
				if (i==zeros.size()-k) res = max(res,sum0[i+k-1]-sum0[i]+zeros[i]+sum1[i+k-2]-sum1[i-1]+ones[i-1]);
				else res = max(res,sum0[i+k-1]-sum0[i]+zeros[i]+sum1[i+k-1]-sum1[i]+ones[i]);
			include <bits/stdc++.h>
using namespace std;

int main() {
    long n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    vector<long> zeros;
    vector<long> ones;
    bool state;
    if (s[0] == '0') state = 0;
    else state = 1;
    long counts = 1;
    for (long i=1; i<n; i++) {
        if (s[i]=='1' && !state) {
            zeros.push_back(counts);
            counts = 1;
            state = !state;
            continue;
        }
        if (s[i]=='0' && state) {
            ones.push_back(counts);
            counts = 1;
            state = !state;
            continue;
        }
        counts++;
    }
    if (state) ones.push_back(counts);
    else zeros.push_back(counts);
    vector<long> sum1(ones.size()), sum0(zeros.size());
    partial_sum(ones.begin(),ones.end(),sum1.begin());
    partial_sum(zeros.begin(),zeros.end(),sum0.begin());
    if (k>=zeros.size()) {
        cout << n;
        return 0;
    }
    bool bottom = 0;
	long res = 0;
    if (zeros.size()>ones.size()) bottom = 1;
    for (long i=0; i<zeros.size()-k+1; i++) {
        if (zeros.size()==ones.size()) res = max(res,sum0[i+k-1]-sum0[i]+zeros[i]+sum1[i+k-1]-sum1[i]+ones[i]);
		else {
			if (bottom) {
				if (i==zeros.size()-k) res = max(res,sum0[i+k-1]-sum0[i]+zeros[i]+sum1[i+k-2]-sum1[i-1]+ones[i-1]);
				else res = max(res,sum0[i+k-1]-sum0[i]+zeros[i]+sum1[i+k-1]-sum1[i]+ones[i]);
			}
			else {
				res = max(res,sum0[i+k-1]-sum0[i]+zeros[i]+sum1[i+k]-sum1[i]+ones[i]);
			}
		}
    }
	cout << res;
    return 0;
}}
			else {
				res = max(res,sum0[i+k-1]-sum0[i]+zeros[i]+sum1[i+k]-sum1[i]+ones[i]);
			}
		}
    }
	cout << res;
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:48:25: error: 'include' was not declared in this scope
   48 |                         include <bits/stdc++.h>
      |                         ^~~~~~~
a.cc:48:34: error: 'bits' was not declared in this scope
   48 |                         include <bits/stdc++.h>
      |                                  ^~~~
a.cc:48:39: error: 'stdc' was not declared in this scope; did you mean 'std'?
   48 |                         include <bits/stdc++.h>
      |                                       ^~~~
      |                                       std
a.cc:49:1: error: expected primary-expression before 'using'
   49 | using namespace std;
      | ^~~~~
a.cc:51:9: warning: empty parentheses were disambiguated as a function declaration [-Wvexing-parse]
   51 | int main() {
      |         ^~
a.cc:51:9: note: remove parentheses to default-initialize a variable
   51 | int main() {
      |         ^~
      |         --
a.cc:51:9: note: or replace parentheses with braces to value-initialize a variable
a.cc:51:12: error: a function-definition is not allowed here before '{' token
   51 | int main() {
      |            ^