n,k,t = map(int,input().split()) s = input() tp = [[0] for _ in range(4)] for p in range(n): for i in range(1,4): tp[i].append(tp[i][-1]+(int(s[p])==i)) def test(w,p): ss1 = tp[1][w+t-1] + (tp[1][-1]-tp[1][p-1]) ss2 = tp[2][w+t-1]-tp[2][w-1] + tp[2][p+t-1]-tp[2][p-1] wg = w-1 + n-(p+t-1) s2 = tp[2][w-1] + tp[2][-1]-tp[2][p+t-1] return ss1,ss2,wg,s2 if k>=tp[1][-1]: #nie musi jechać do pracy print(n-max(n-tp[3][-1]-k,0)) else: ans = -1 for w in range(1,n-2*t+2): for p in range(w+t,n-t+2): ss1,ss2,wg,s2 = test(w,p) if ss1+ss2>k: continue gp = wg-max(s2-(k-(ss1+ss2)),0) ans = max(ans,gp) print(ans)
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 | n,k,t = map(int,input().split()) s = input() tp = [[0] for _ in range(4)] for p in range(n): for i in range(1,4): tp[i].append(tp[i][-1]+(int(s[p])==i)) def test(w,p): ss1 = tp[1][w+t-1] + (tp[1][-1]-tp[1][p-1]) ss2 = tp[2][w+t-1]-tp[2][w-1] + tp[2][p+t-1]-tp[2][p-1] wg = w-1 + n-(p+t-1) s2 = tp[2][w-1] + tp[2][-1]-tp[2][p+t-1] return ss1,ss2,wg,s2 if k>=tp[1][-1]: #nie musi jechać do pracy print(n-max(n-tp[3][-1]-k,0)) else: ans = -1 for w in range(1,n-2*t+2): for p in range(w+t,n-t+2): ss1,ss2,wg,s2 = test(w,p) if ss1+ss2>k: continue gp = wg-max(s2-(k-(ss1+ss2)),0) ans = max(ans,gp) print(ans) |