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

int numOfEvent[4][8002];

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    int n, k, t, ans = -1;
    char c;
    cin >> n >> k >> t;
    for(int i = 1 ; i <= n ; i++){
        cin >> c;
        for(int j = 1 ; j <= 3 ; j++) numOfEvent[j][i] = numOfEvent[j][i - 1];
        numOfEvent[c - '0'][i]++;
    }
    if(numOfEvent[1][n] <= k){
        cout << n - numOfEvent[2][n] - numOfEvent[1][n] + min(k, numOfEvent[2][n] + numOfEvent[1][n]) << '\n';
        return 0;
    }
    int programing, skipped, workFromHome;
    for(int i = 1 ; i <= n - 2 * t ; i++){
        for(int j = i + t ; j <= n - t ; j++){
            programing = numOfEvent[3][i - 1] + numOfEvent[1][i - 1] + numOfEvent[3][n] + numOfEvent[1][n] - numOfEvent[3][j + t] - numOfEvent[1][j + t];
            skipped = numOfEvent[1][i + t - 1] + numOfEvent[2][i + t - 1] - numOfEvent[2][i - 1] + numOfEvent[1][n] - numOfEvent[1][j] + numOfEvent[2][j + t] - numOfEvent[2][j];
            workFromHome = numOfEvent[2][i - 1] + numOfEvent[2][n] - numOfEvent[2][j + t];
            if(skipped <= k) ans = max(ans, programing + min(k - skipped, workFromHome));
        }
    }
    cout << ans << '\n';
}