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
#include <iostream>
#include <vector>
#include <algorithm>

int main() {
    int n, k, t;
    std::cin >> n >> k >> t;
    std::string schedule;
    std::cin >> schedule;

    std::vector<int> dp(n + 1, -1);
    dp[0] = 0;

    for (int i = 0; i < n; ++i) {
        if (dp[i] == -1) continue;

        if (schedule[i] == '3') {
            dp[i + 1] = std::max(dp[i + 1], dp[i] + 1);
        } else {
            dp[i + 1] = std::max(dp[i + 1], dp[i]);
        }

        if (i + t < n) {
            int missedMeetings = 0;
            for (int j = i + 1; j <= i + t; ++j) {
                if (schedule[j] == '1') ++missedMeetings;
            }
            if (missedMeetings <= k) {
                dp[i + t + 1] = std::max(dp[i + t + 1], dp[i]);
            }
        }
    }

    int maxTasks = *std::max_element(dp.begin(), dp.end());
    std::cout << (maxTasks == -1 ? -1 : maxTasks) << std::endl;

    return 0;
}