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

using namespace std;

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

    int n, k, t;

    cin >> n >> k >> t;

    string input;

    cin >> input;

    vector<int> offline;
    vector<int> online;
    offline.push_back(0);
    online.push_back(0);

    for (int i = 0; i < input.length(); i++) {
        offline.push_back(offline.back());
        online.push_back(online.back());
        if (input[i] == '1') {
            offline[i+1]++;
        } else if (input[i] == '2') {
            online[i+1]++;
        } else {

        }
    }
    offline.push_back(offline.back());
    online.push_back(online.back());
    int totalMeetings = offline.back() + online.back();

    if (offline.back() <= k) {
        cout << n - max(totalMeetings - k, 0) << endl;
    } else {
        int bestRes = -1;
        for (int i = t+1; i < n - t + 1; i++) {
            for (int j = i; j < n - t + 1; j++) {
                int officeMeetings = (offline[j] - offline[i-1]) + (online[j] - online[i-1]);
                int maxMeetings = online.at(i-t-1) + officeMeetings + online.back() - online[j+t];

                if (totalMeetings - maxMeetings <= k) {
                    if (totalMeetings - officeMeetings <= k) {
                        bestRes = max(bestRes, i-t-1 + n-j-t);
                    } else {
                        bestRes = max(bestRes, i-t-1 + n-j-t - (totalMeetings - officeMeetings - k));
                    }
                }
            }
        }
        cout << bestRes << endl;
    }

    return 0;
}