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
71
72
73
74
75
76
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

void increase(const string &s, int i, int &cntWork, int &cntFree) {
	if(s[i] == '2') {
		cntWork++;
	}
		
	if(s[i] == '3') {
		cntFree++;
	}
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int n, k, t;
	cin >> n >> k >> t;
	string s;
	cin >> s;
	
	vector<int> sufWork(n+1), sufFree(n+1);
	int cntWork = 0, cntFree = 0;
	
	for(int i = n-1; i >= 0; i--) {
		increase(s, i, cntWork, cntFree);
		
		sufWork[i] = cntWork;
		sufFree[i] = cntFree;
	}
	
	int meetingsNeed = max(n - cntFree - k, 0);
	
	if(cntWork >= meetingsNeed) {
		cout << cntFree + (n - cntFree - meetingsNeed) << "\n";
		return 0;
	}
	
	cntWork = 0;
	cntFree = 0;
	
	int ans = -1;
	for(int i = 0; i < n; i++) {
		int cntWorkJ = 0;
		
		for(int j = i+t; j < n; j++) {
			int posEnd = j+t;
			
			if(posEnd-1 >= n) {
				break;
			}

			int totalWork = cntWork + cntWorkJ + sufWork[posEnd];
			int totalFree = cntFree + sufFree[posEnd];
			
			if(totalWork >= meetingsNeed) {
				ans = max(ans, totalFree);
			}

			if(s[j] == '1' || s[j] == '2') {
				cntWorkJ++;
			}
		}
		
		increase(s, i, cntWork, cntFree);
	}

	cout << ans << "\n";
	
	return 0;
}