Language: C++

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;

class CumulativeSumClass {
public:
    CumulativeSumClass(vector<int> const data) :
        Sum(data.size()+1, 0)
    {
        for (size_t i = 0; (i < data.size()); ++i) {
            Sum[i+1] = Sum[i] + data[i];
        }
    }
    int GetSum(size_t const leftIdx, size_t const rightIdx) const
    {
        return Sum[rightIdx+1] - Sum[leftIdx];
    }
private:
    vector<int> Sum;
};

int main()
{
    ll n, k;
    string str;
    cin >> n >> k >> str;
    vector<ll> ary;

    char prev = 0xff;
    if (str[0] == '0') {
        ary.push_back(0);
        prev = '1';
    }
    for (ll i = 0; (i < n); i++) {
        char curr = str[i];
        if (prev != curr) {
            prev = curr;
            ary.push_back(1);
        } else {
            ary[ary.size()-1]++;
        }
    }
    if (str[n-1] == '0') ary.push_back(0);

  CumulativeSumClass sum(ary);

    ll maxv = 0;
    for(ll i = 0; (i < ary.size()); i+=2) {
        ll left = i;
        ll right = min((ll)(ary.size()-1), i+k*2);
        maxv = max(maxv, sum.GetSum(left, right));
    }
    cout << maxv << endl;
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:47:29: error: no matching function for call to 'CumulativeSumClass::CumulativeSumClass(std::vector<long long int>&)'
   47 |   CumulativeSumClass sum(ary);
      |                             ^
a.cc:9:5: note: candidate: 'CumulativeSumClass::CumulativeSumClass(std::vector<int>)'
    9 |     CumulativeSumClass(vector<int> const data) :
      |     ^~~~~~~~~~~~~~~~~~
a.cc:9:42: note:   no known conversion for argument 1 from 'vector<long long int>' to 'vector<int>'
    9 |     CumulativeSumClass(vector<int> const data) :
      |                        ~~~~~~~~~~~~~~~~~~^~~~
a.cc:7:7: note: candidate: 'CumulativeSumClass::CumulativeSumClass(const CumulativeSumClass&)'
    7 | class CumulativeSumClass {
      |       ^~~~~~~~~~~~~~~~~~
a.cc:7:7: note:   no known conversion for argument 1 from 'std::vector<long long int>' to 'const CumulativeSumClass&'
a.cc:7:7: note: candidate: 'CumulativeSumClass::CumulativeSumClass(CumulativeSumClass&&)'
a.cc:7:7: note:   no known conversion for argument 1 from 'std::vector<long long int>' to 'CumulativeSumClass&&'
a.cc:53:19: error: no matching function for call to 'max(ll&, int)'
   53 |         maxv = max(maxv, sum.GetSum(left, right));
      |                ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:53:19: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   53 |         maxv = max(maxv, sum.GetSum(left, right));
      |                ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303: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:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:53:19: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   53 |         maxv = max(maxv, sum.GetSum(left, right));
      |                ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~