1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <bits/stdc++.h>
using namespace std;

const int N = 8e3 + 5;

int n, k, t;
string s;
int p[3][N];

int get(int idx, int l, int r){
    if(l > r) return 0;
    return p[idx][r] - (l == 0 ? 0 : p[idx][l-1]);
}

int main(){
    cin.tie(0)->sync_with_stdio(0);

    cin >> n >> k >> t >> s;

    int cnt = 0;
    for(auto c : s){
        cnt += c != '3';
    }

    int ans = -1;

    for(int k=1;k<=2;k++){
        for(int i=0;i<n;i++){
            p[k][i] = (i == 0 ? 0 : p[k][i-1]) + (s[i] == '0' + k);
        }
    }

    if(get(1, 0, n-1) <= k){
        ans = max(ans, n - max(0,get(2,0,n-1)-(k-get(1,0,n-1))));
    }

    for(int i=t;i<n;i++){
        for(int j=i;j<n-t;j++){
            int cnt2 = get(1,i,j) + get(2,i,j);
            int cnt3 = get(2,0,i-t-1) + get(2,j+t+1,n-1);
            if(cnt - (cnt2 + cnt3) <= k){
                int lef = cnt - k;
                lef -= cnt2;
                ans = max(ans, i-t + n-1-(j+t) - max(0, lef));
            }
        } 
    }

    cout << ans << "\n";

    return 0;
}