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
#include <bits/stdc++.h>

using namespace std;
#define pb push_back
#define st first
#define nd second
typedef long long ll;
typedef long double ld;
const ll I = 1000'000'000'000'000'000LL;
const int II = 2'000'000'000;
const ll M = 1000'000'007LL;
const int N = 8'007;
int t1[N], t2[N];
string s;

void Solve()
{
    int n, k, t;
    cin >> n >> k >> t;
    cin >> s;
    for(int i = 1; i <= n; ++i)
    {
        t1[i] = t1[i - 1] + (int)(s[i - 1] == '1');
        t2[i] = t2[i - 1] + (int)(s[i - 1] == '2');
    }
    k = (t1[n] + t2[n]) - k;
    k = max(0, k);
    if(t2[n] >= k)
        {cout << n - k << "\n"; return;}
    int ans = -1;
    for(int i = t; i <= n - t; ++i)
        for(int j = i + 1; j <= n - t; ++j)
        {
            int x = t2[j] - t2[i] + t1[j] - t1[i];
            if((t2[i - t] + x + t2[n] - t2[j + t]) >= k)
                ans = max(ans, (i - t) + (n - (j + t)) - (k - min(x, k)));
        }
    cout << ans << "\n";
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    //int t; cin >> t;
    //while(t--)
        Solve();

    return 0;
}