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

const int INF = 1e9;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    int n, k, t;
    cin >> n >> k >> t;
    string plan;
    cin >> plan;
    
    vector<vector<int>> dp(n + 1, vector<int>(2, -INF));
    dp[0][0] = 0; 
    
    for (int i = 0; i < n; i++) {
        for (int loc = 0; loc < 2; loc++) {
            if (dp[i][loc] == -INF) continue;
            
            int nowe_punkty = dp[i][loc];
            if (loc == 0) { // W domu
                if (plan[i] == '3') nowe_punkty++; 
            }
            dp[i + 1][loc] = max(dp[i + 1][loc], nowe_punkty);
            
            if (loc == 0 && i + t < n) {
                dp[i + t][1] = max(dp[i + t][1], dp[i][0]);
            }
            if (loc == 1 && i + t < n) {
                dp[i + t][0] = max(dp[i + t][0], dp[i][1]);
            }
        }
    }
    
    int wynik = max(dp[n][0], dp[n][1]);
    if (wynik < 0) cout << -1 << '\n';
    else cout << wynik << '\n';
    
    return 0;
}