Language: C++

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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  ll n,k;
  string s;
  cin >> n >> k;
  cin >> s;

  vll value(n, 0);
  ll now = s[0];
  ll cur = 0;
  ll counter = 1;
  REP1(i, n){
    if(s[i] != s[i-1]){
      value[cur] = counter;
      cur++;
      now = s[i];
      counter = 1;
    }
    else
      counter++;
  }
  value[cur] = counter;

  cur++;
  pll sum = make_pair(value[0], value[1]);
  REP(i, min((cur-1)/2, k))
    sum.FI += value[2*i+1] + value[2*i+2];


  ll ans = sum;
  for(ll i = 1; i <= cur+1-min(n,k); i++){
    sum += value[i+k-1];
    sum -= value[i-1];
    ans = max(ans, sum);
  }

  cout << ans << endl;




  
  
}


Compiler output:
a.cc: In function 'int main()':
a.cc:68:12: error: cannot convert 'pll' {aka 'std::pair<long long int, long long int>'} to 'll' {aka 'long long int'} in initialization
   68 |   ll ans = sum;
      |            ^~~
      |            |
      |            pll {aka std::pair<long long int, long long int>}
a.cc:70:9: error: no match for 'operator+=' (operand types are 'pll' {aka 'std::pair<long long int, long long int>'} and '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'})
   70 |     sum += value[i+k-1];
a.cc:71:9: error: no match for 'operator-=' (operand types are 'pll' {aka 'std::pair<long long int, long long int>'} and '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'})
   71 |     sum -= value[i-1];
a.cc:72:14: error: no matching function for call to 'max(ll&, pll&)'
   72 |     ans = max(ans, sum);
      |           ~~~^~~~~~~~~~
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: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:72:14: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'pll' {aka 'std::pair<long long int, long long int>'})
   72 |     ans = max(ans, sum);
      |           ~~~^~~~~~~~~~
/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:
/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:72:14: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   72 |     ans = max(ans, sum);
      |           ~~~^~~~~~~~~~