class Solution {
public:
    /**
     * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
     *
     * 
     * @param n int 
     * @param m int 
     * @param a intvector 
     * @return int
     */

    int solve(int n, int m, vector<int>& a) {
         int sum = 0,ans = 0,l = 0;
            for(int i = 0; i < n; i++) {
                if(a[i] == 0)
                    sum++;
                while(sum > m) {
                    if(a[l] == 0)
                        sum--;
                    l++;    
                }
                ans = max(ans,i - l + 1);
            }
            return ans;
    }
};