1-Count Problem WHY AM I GETTING WRONG ANSWER FOR TWO TEST CASE IN "1 COUNT DP" PROBLEM

THIS IS MY SOLUTION PLEASE TELL ME WHY I AM GETTING WRONG ANSWER IN THE FIRST TWO TEST CASES

#include <bits/stdc++.h>
using namespace std;
long long int a[1000010],prefix[1000010];
int main() {
// your code goes here
long long int i,j,k,l,m,n,o,p,q,r,s,t,e,mid;
cin>>n>>k;
prefix[0]=0;
for(i=1;i<=n;i++)
{
cin>>a[i];
prefix[i]=prefix[i-1];
if(a[i]==0)
prefix[i]+=1;
}
m=-10000000;
l=0;
r=0;
for(i=1;i<=n;i++)
{
s=i;
e=n;
while(s<=e)
{
mid=(s+e)/2;
if(prefix[mid]-prefix[i-1]<=k)
{
j=mid;
s=mid+1;
}
else
{
e=mid-1;
}
}
if(j>n)
j=n;
if(j-i+1>m)
{
l=i;
r=j;
m=j-i+1;
}
}
for(i=l;i<=r;i++)
{
a[i]=1;
}
cout<<m<<endl;
for(i=1;i<=n;i++)
cout<<a[i]<<" ";
cout<<endl;
return 0;
}

Please respond here on the doubt on dynamic programming