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
66
67
68
69
70
// PA2025, @mjm, r1b-pra

#include <cstdio>
#include <vector>
using namespace std;
int nextInt() { int n; scanf("%d", &n); return n; }

const int N = 8000 + 9;

int n;
int k;
int t;
char buf[N];
int s1[N];
int s2[N];

inline int sum1(int be, int en) { return s1[en] - s1[be]; }
inline int sum2(int be, int en) { return s2[en] - s2[be]; }
inline int myMax(int a, int b) { return a >= b ? a : b; }

int solve() {
	if (k <= sum2(0, n))
		// all day at home
		return n - k;

	int res = -1;

	for (int be = 0; be < n; ++be) {
		for (int en = be + t + t + 1; en <= n; ++en) {
			int officeAttendCount = 0;
			officeAttendCount += sum1(be + t, en - t);
			officeAttendCount += sum2(be + t, en - t);

			int maxAttendCount = officeAttendCount;
			maxAttendCount += sum2(0, be);
			maxAttendCount += sum2(en, n);

			if (maxAttendCount < k) continue; // impossible
			int homeTime = be + (n - en);
			if (officeAttendCount < k)
				homeTime -= k - officeAttendCount;
			res = myMax(res, homeTime);
		}
	}

	return res;
}

int main() {
	n = nextInt();
	k = nextInt();
	t = nextInt();
	s1[0] = s2[0] = 0;
	scanf("%s", buf);

	for (int i = 0; i < n; ++i) {
		s1[i + 1] = s1[i];
		s2[i + 1] = s2[i];
		if ('1' == buf[i]) ++s1[i + 1];
		if ('2' == buf[i]) ++s2[i + 1];
	}

	k = sum1(0, n) + sum2(0, n) - k;
	if (k < 0) k = 0;

	int res = solve();
	printf("%d\n", res);

	return 0;
}