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
#include <iostream>
#include <vector>
#include <algorithm>
int n,k,t;
char c;
int main() {
    std::ios_base::sync_with_stdio(0);
    std::cin.tie(NULL);
    std::cin>>n>>k>>t;
    std::vector<int> p[4];
    for(int j=1;j<4;j++)
        p[j].emplace_back(0);
    for(int i=0;i<n;i++){
        std::cin>>c;
        int num=c-'0';
        for(int j=1;j<4;j++)
            p[j].emplace_back(p[j][i]+(num==j));
    }
    if(p[1][n]<=k){
        std::cout<<n-std::max(p[1][n]+p[2][n]-k,0)<<"\n";
        return 0;//not go to work
    }
    int best=-1;
    for(int st=1;st<=n;st++)
        for(int ko=st+2*t;ko<=n;ko++){
            int miss=p[1][st+t-1]+p[1][n]-p[1][ko-t]+p[2][st+t-1]-p[2][st-1]+p[2][ko]-p[2][ko-t];
            //std::cerr<<st<<" "<<ko<<" "<<miss<<std::endl;
            if(miss<=k){
                int res=p[3][st-1]+p[3][n]-p[3][ko]+p[1][st-1]+p[1][n]-p[1][ko]+k-miss;
                if(res>best)
                    best=res;
            }
        }
    std::cout<<best<<"\n";
}