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
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define deb(...)
#define DBP(...)
using namespace std;
using   ll         = long long;
using   vi         = vector<int>;
using   pii        = pair<int, int>;
#define pb           push_back
#define mp           make_pair
#define x            first
#define y            second
#define rep(i, b, e) for (int i = (b); i < (e); i++)
#define each(a, x)   for (auto& a : (x))
#define all(x)       (x).begin(), (x).end()
#define sz(x)        int((x).size())

void run();

int main() {
	cin.sync_with_stdio(0); cin.tie(0);
	cout << fixed << setprecision(12);
	run();
	cout << flush; _Exit(0);
}

void run() {
	int n, k, t;
	string s;
	cin >> n >> k >> t >> s;

	vector<int> any(n+1), remote(n+1);
	rep(i, 0, n) {
		any[i+1] = any[i] + (s[i] <= '2');
		remote[i+1] = remote[i] + (s[i] == '2');
	}

	int ans = -1;
	k = max(any[n]-k, 0);

	if (remote[n] >= k) {
		ans = n-k;
	} else {
		rep(b, t, n+1) rep(e, b, n-t+1) {
			int req = max(k - (any[e]-any[b]), 0);
			int avail = remote[b-t] + remote[n] - remote[e+t];
			if (avail >= req) {
				ans = max(ans, b-t + n - (e+t) - req);
			}
		}
	}

	cout << ans << '\n';
}