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
#include <cstdio>
#include <vector>
#include <map>

using namespace std;

int ma[8000];
int mh[8000];

int main()
{
	int n, k, t;
	char c;
	scanf("%d %d %d\n", &n, &k, &t);
	for (int i = 0; i < n; i++)
	{
		scanf("%c", &c);
		if (c < '1' || c>'3')
		{
			i--;
		}

		ma[i] = (i > 0 ? ma[i-1] : 0) + (c != '3' ? 1 : 0);
		mh[i] = (i > 0 ? mh[i-1] : 0) + (c == '2' ? 1 : 0);
	}

	int m2p = ma[n - 1] - k;
	if (m2p < 0) {
		m2p = 0;
	}
	if (mh[n - 1] >= m2p)
	{
		printf("%d\n", n - m2p);
		return 0;
	}
	int res = -1;
	for (int i = 0; i < n - 2 * t; i++)
	{
		for (int j = t; j <= n - t; j++)
		{
			if ((i>0?mh[i-1]:0) + ma[j-1] - ma[i + t-1] + mh[n - 1] - mh[j + t-1] >= m2p)
			{
				int w = i  - mh[i] + n - j - t - (mh[n - 1] - mh[j + t - 1]);
				if (res < w)
				{
					res = w;
				}
				break;
			}
		}
	}
		printf("%d\n", res);


		
	
	return 0;
}