Language: C++

int main(){
    int N,K;
    cin >> N >> K;
    string S;
    cin >> S;
    
    vector<int> v; // 1-0-1-.....-0-1
    int count=0;
    char now01 = '1';//最初が0だった時にv[0]に0が入る
    
    for(int i=0; i<N; i++){
        if(S[i]==now01){
            count++;
            
        }else{
            v.push_back(count);
            count = 1;
            now01 = S[i];
        }
    }
    if(count != 0)v.push_back(count);
    if(v.size() % 2 == 0)v.push_back(0); //1-0-1-...-0の時に最後に0を入れる
    
    int L = (int)v.size();
    
    vector<int> sum_array;
    int sum=0;
    for(int i=0; i<L; i++){
        sum += v[i];
        sum_array.push_back(sum);
    }
    
    int max_v=0;

    if(K*2 >= L){
        max_v = max(max_v, sum_array[L-1]);
    }
    
    for(int i=0; i<L-K*2; i+=2){
        if(i==0){
            max_v = max(max_v, sum_array[i+K*2]);
        }else{
            max_v = max(max_v, sum_array[i+K*2] - sum_array[i-1]);
        }
    }
    
    cout << max_v << endl;

    return 0;
}




Compiler output:
a.cc: In function 'int main()':
a.cc:3:5: error: 'cin' was not declared in this scope
    3 |     cin >> N >> K;
      |     ^~~
a.cc:4:5: error: 'string' was not declared in this scope
    4 |     string S;
      |     ^~~~~~
a.cc:5:12: error: 'S' was not declared in this scope
    5 |     cin >> S;
      |            ^
a.cc:7:5: error: 'vector' was not declared in this scope
    7 |     vector<int> v; // 1-0-1-.....-0-1
      |     ^~~~~~
a.cc:7:12: error: expected primary-expression before 'int'
    7 |     vector<int> v; // 1-0-1-.....-0-1
      |            ^~~
a.cc:16:13: error: 'v' was not declared in this scope
   16 |             v.push_back(count);
      |             ^
a.cc:21:19: error: 'v' was not declared in this scope
   21 |     if(count != 0)v.push_back(count);
      |                   ^
a.cc:22:8: error: 'v' was not declared in this scope
   22 |     if(v.size() % 2 == 0)v.push_back(0); //1-0-1-...-0の時に最後に0を入れる
      |        ^
a.cc:24:18: error: 'v' was not declared in this scope
   24 |     int L = (int)v.size();
      |                  ^
a.cc:26:12: error: expected primary-expression before 'int'
   26 |     vector<int> sum_array;
      |            ^~~
a.cc:30:9: error: 'sum_array' was not declared in this scope
   30 |         sum_array.push_back(sum);
      |         ^~~~~~~~~
a.cc:36:28: error: 'sum_array' was not declared in this scope
   36 |         max_v = max(max_v, sum_array[L-1]);
      |                            ^~~~~~~~~
a.cc:36:17: error: 'max' was not declared in this scope; did you mean 'max_v'?
   36 |         max_v = max(max_v, sum_array[L-1]);
      |                 ^~~
      |                 max_v
a.cc:41:32: error: 'sum_array' was not declared in this scope
   41 |             max_v = max(max_v, sum_array[i+K*2]);
      |                                ^~~~~~~~~
a.cc:41:21: error: 'max' was not declared in this scope; did you mean 'max_v'?
   41 |             max_v = max(max_v, sum_array[i+K*2]);
      |                     ^~~
      |                     max_v
a.cc:43:32: error: 'sum_array' was not declared in this scope
   43 |             max_v = max(max_v, sum_array[i+K*2] - sum_array[i-1]);
      |                                ^~~~~~~~~
a.cc:43:21: error: 'max' was not declared in this scope; did you mean 'max_v'?
   43 |             max_v = max(max_v, sum_array[i+K*2] - sum_array[i-1]);
      |                     ^~~
      |                     max_v
a.cc:47:5: error: 'cout' was not declared in this scope; did you mean 'count'?
   47 |     cout << max_v << endl;
      |     ^~~~
      |     count
a.cc:47:22: error: 'endl' was not declared in this scope
   47 |     cout << max_v << endl;
      |                      ^~~~