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
53
54
55
56
57
58
59
60
61
62
63
64
65
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using pi=pair<int,int>;
using vi=vector<int>;
using vl=vector<ll>;
using vpi=vector<pi>;
#define mp make_pair
#define eb emplace_back
#define x first
#define y second
#define sz(x)int((x).size())
#define all(x)(x).begin(),(x).end()
#define rep(i,a,b)for(int i=(a);i<(b);i++)
#define per(i,a,b)for(int i=(b)-1;i>=(a);i--)
bool ckmin(auto&a,auto b){return b<a?a=b,1:0;}
bool ckmax(auto&a,auto b){return b>a?a=b,1:0;}
#ifdef LOCAL
auto&operator<<(auto&o,pair<auto,auto>p){return o<<"("<<p.x<<", "<<p.y<<")";}
auto operator<<(auto&o,auto x)->decltype(x.end(),o){o<<"{";int i=0;for(auto&e:x)o<<","+!i++<<e;return o<<"}";}
#define debug(X...)cerr<<"["#X"]: ",[](auto...$){((cerr<<$<<"; "),...)<<endl;}(X);
#else
#define debug(...){}
#endif

signed main() {
    cin.tie(0)->sync_with_stdio(0);
    
    int n, k, t;
    string s;
    cin >> n >> k >> t >> s;
    
    int remote = 0, office = 0;
    rep(i, 0, n) {
        if (s[i] == '1') office++;
        else if (s[i] == '2') remote++;
    }
    int total = remote + office;
    
    int res = -1;
    if (office <= k) {
        if (total <= k) res = n;
        else res = n - (total - k);
    }
    
    rep(l, 0, n - 2 * t) {
        int ava_office = 0, ava_remote = 0;
        rep(i, 0, l) if (s[i] == '2') ava_remote++;
        rep(i, l + 2 * t, n) if (s[i] == '2') ava_remote++;
        
        rep(r, l + t, n + 1 - t) {
            if (ava_office + ava_remote >= total - k) {
                int least = max(0, total - k - ava_office);
                ckmax(res, l + n - (r + t) - least);
            }
            
            if (s[r] == '1' || s[r] == '2') ava_office++;
            if (r + t < n && s[r + t] == '2') ava_remote--;
        }
    }
    
    cout << res << "\n";
    
    return 0;
}