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
#include <iostream>

int e(std::string &s, int a, int b, int d, int k) {
    int count = 0;
    int free = 0;
    int maybe = 0;
    // how many conflicts
    // travel time
    for (int j = 0; j < d; j++) {
        if (a+j>=s.size()) break;
        if (s[a+j] != '3') count++;
        if (s[b+j] != '3') count++;
    }
    // home time
    for (int j = 0; j < a; j++) {
        if (s[j]=='1') count++;
        if (s[j]=='2') maybe++;
        if (s[j]!='2') free++;
    }
    for (int j = b+d; j < s.size(); j++) {
        if (s[j]=='1') count++;
        if (s[j]=='2') maybe++;
        if (s[j]!='2') free++;
    }
    // std::cout << a << " " << b << " " << count << " / " << free << "+" << maybe << std::endl;
    if (count > k) return -1;
    while (count < k && maybe > 0) {
        maybe--;
        count++;
        free++;
    }
    return free;
}

int main() {
    int n, k, t;
    std::cin >> n >> k >> t;
    std::string s;
    std::cin >> s;
    int m = e(s, n, n, t, k);
    for (int a = 0; a <= n - 2 * t; a++) {
        for (int b = a + t; b <= n - t; b++) {
            int mm = e(s, a, b, t, k);
            m = std::max(m, mm);
        }
    }
    std::cout << m << std::endl;  
    return 0;
}