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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int main() {
    cin.tie(0)->sync_with_stdio(0);
    int n, may_skip, commute, total_meetings = 0;
    cin >> n >> may_skip >> commute;
    vector<int> events(n), in_office{0}, remote{0};
    for(auto &i : events) {
        char c;
        cin >> c;i = c-'0';
        total_meetings += (i != 3);
        in_office.push_back(in_office.back() + (i == 1));
        remote.push_back(remote.back() + (i == 2));
    }

    int must_attend = max(0, total_meetings - may_skip), ans = -1;
    if(remote.back() >= must_attend) {
        ans = n - must_attend;
    }
    for(int start = 1; start + commute - 1 <= n; start++) {
        for(int finish = start + commute; finish + commute - 1 <= n; finish++) {
            /*
            Always attend all meetings in the office
            But can also attend remotes
            */
            int attend_min = 0;
            attend_min += in_office[finish - 1] - in_office[start + commute - 1];
            attend_min += remote[finish - 1] - remote[start + commute - 1];
            
            int attend_extra = remote[start - 1] + (remote.back() - remote[finish + commute - 1]);
            
            int need_extra = max(must_attend - attend_min, 0);
            int time_home = (start - 1) + (n - (finish + commute - 1));
            if(need_extra <= attend_extra) {
                ans = max(ans, time_home - need_extra);
            }
        }
    }
    cout << ans << '\n';
}