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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include <bits/stdc++.h>
#define st first
#define nd second
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define fr(i,n) for(int i=0; i<(n); i++)
#define frx(i,a,b) for(int i=(a); i<=(b); i++)
#define ok(cond) cout << ((cond) ? "Yes" : "No") << "\n";
#define watch(x) cerr << (#x) << " == " << (x) << endl;
using namespace std;
typedef long long ll;
typedef long double ld;
typedef const int ci;
typedef const ll cll;
typedef const ld cld;
typedef pair<int,int> pii;
typedef set<int> si;
typedef vector<int> vi;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<int,ll>> vpill;


template<typename T1, typename T2>
istream& operator>>(istream& is, pair<T1,T2>& p) {
    return is >> p.st >> p.nd;
}

template<typename T1, typename T2>
ostream& operator<<(ostream& os, pair<T1,T2>& p) {
    return os << p.st << " " << p.nd;
}


template<typename T>
ostream& operator<<(ostream& os, vector<T>& v) {
    for (T x : v) {
        os << x << " ";
    }
    return os;
}

template<typename T>
ostream& operator<<(ostream& os, set<T>& s) {
    for (T x : s) {
        os << x << " ";
    }
    return os;
}

const int N = 8e3;
int cnt[3][N+5];

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int n, k, t;
    cin>>n>>k>>t;

    fr(i,n) {
        char c;
        cin>>c;
        cnt[c-'1'][i+1] = 1;
        fr(j,3) {
            cnt[j][i+1] += cnt[j][i];
        }
    }

    int min_meets = cnt[0][n] + cnt[1][n] - k;

    if (cnt[0][n] <= k) {
        cout << cnt[2][n] + min(cnt[0][n] + cnt[1][n], k) << "\n";
        return 0;
    }

    int mmax = -1;
    frx(beg, t+1, n-t) {
        frx(end, beg, n-t) {
            int in_office_meets = cnt[0][end] - cnt[0][beg-1]
                                + cnt[1][end] - cnt[1][beg-1];
            int remote_meets = cnt[1][n] - cnt[1][end+t] + cnt[1][beg-t-1];
            if (in_office_meets + remote_meets >= min_meets) {
                remote_meets = max(0, min_meets - in_office_meets);
                mmax = max(mmax, n - (end+t) + (beg-t-1) - remote_meets);
            }
        }
    }

    cout << mmax << "\n";

    return 0;
}