intSolution::solve(vector<int> &A, int B){ int res = 0, l = 0, r = 0, n = A.size(), now = 0; while(r < n) { while(r < n and now <= B) { res = max(res, r - l); if(A[r++] == 0) now += 1; } if(now <= B) res = max(res, r - l); while(now > B) { if(A[l++] == 0) now -= 1; } } return res; }