Language: C++

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

int main(void)
{
    int n, k, counter = 0, longest = 0;
    string str;
    cin >> n >> k >> str;
    bool flag = 0;
    bool flag_beginning = 0;
    bool flag_last = 0;
    vector<int> one, zero;

    if (str.at(0) == '1')
    {
        flag_beginning = 1;
        flag = 1;
    }
    if (str.at(n - 1) == '1')
    {
        flag_last = 1;
    }

    for (int i = 1; i < n; i++)
    {
        if (str.at(i) == str.at(i - 1))
        {
            counter++;
            if (i == n - 1)
            {
                if (flag)
                {
                    one.push_back(counter + 1);
                    flag = 0;
                }
                else
                {
                    zero.push_back(counter + 1);
                    flag = 1;
                }
            }
        }
        else
        {
            if (i == n - 1)
            {
                if (flag)
                {
                    one.push_back(counter + 1);
                    zero.push_back(1);
                    flag = 0;
                }
                else
                {
                    zero.push_back(counter + 1);
                    one.push_back(1);
                    flag = 1;
                }
            }
            else
            {
                if (flag)
                {
                    one.push_back(counter + 1);
                    flag = 0;
                }
                else
                {
                    zero.push_back(counter + 1);
                    flag = 1;
                }
            }
            counter = 0;
        }
    }

    if (zero.size() == 0)
    {
        cout << n << endl;
    }
    else if (one.size() == 0)
    {
        if (k == 0)
        {
            cout << 0 << endl;
        }
        else
        {
            cout << n << endl;
        }
    }
    else
    {
        if(zero.size>k-1){
            cout << n << endl;
        }else{
        //RE
        if (flag_beginning == 0)
        {
            for (int j = 0; j < k; j++)
            {
                longest += zero.at(j);
                longest += one.at(j);
            }
        }

        //RE
        for (int i = 0; i < one.size() - k; i++)
        {
            int sum = 0;
            for (int j = 0; j < k; j++)
            {
                sum += zero.at(i + j + (1 - flag_beginning));
                sum += one.at(i + j);
            }
            sum += one.at(i + k);
            if (sum > longest)
            {
                longest = sum;
            }
        }
        }

        //OK
        if (flag_last == 0)
        {
            reverse(zero.begin(), zero.end());
            reverse(one.begin(), one.end());
            int sum = 0;
            for (int j = 0; j < k; j++)
            {
                sum += zero.at(j);
                sum += one.at(j);
            }
            if (sum > longest)
            {
                longest = sum;
            }
        }

        cout << longest << endl;
    }

    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:94:17: error: invalid use of member function 'std::vector<_Tp, _Alloc>::size_type std::vector<_Tp, _Alloc>::size() const [with _Tp = int; _Alloc = std::allocator<int>; size_type = long unsigned int]' (did you forget the '()' ?)
   94 |         if(zero.size>k-1){
      |            ~~~~~^~~~
      |                     ()