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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, k, t; cin >> n >> k >> t;
    string s; cin >> s;
    vector<vector<int>> cnt(3, vector<int>(n, 0));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 3; j++) cnt[j][i] = (i ? cnt[j][i - 1] : 0);
        cnt[s[i] - '1'][i]++;
    }
    int meetings = cnt[0][n - 1] + cnt[1][n - 1];
    k = max(0, meetings - k);
    int ans = -1;
    if (cnt[1][n - 1] >= k) ans = n - k;
    for (int i = 0; i < n; i++) {
        for (int j = i; j < n; j++) {
            if (i < t || (n - j - 1) < t) continue;
            int in_office = cnt[0][j] - (i ? cnt[0][i - 1] : 0) + cnt[1][j] - (i ? cnt[1][i - 1] : 0);
            int other = ((i - t) ? cnt[1][i - t - 1] : 0) + cnt[1][n - 1] - cnt[1][j + t];
            if ((in_office + other) >= k) {
                int time_in_office = j - i + 1 + 2 * t;
                int rem = max(0, k - in_office);
                // printf("(%d, %d) - in_office = %d, other = %d, rem = %d, time_in_office = %d, cand = %d\n", i, j, in_office, other, rem, time_in_office, (n - time_in_office) - rem);
                ans = max(ans, (n - time_in_office) - rem);
            }
        }
    }
    cout << ans << "\n";
}