Help me to solve Starters 116 Div 4 C problem Access Control

include <bits/stdc++.h>
using namespace std;
void solve()
{

int n,x,countswipe=0,flag=1;
cin>>n>>x;
string s;
cin>>s;
for(int i=0;i<n;i++)
{
    if(s[i]=='1')
    {
        countswipe+=x;

    }
    else if(s[i]=='0'){
            countswipe-=1;
            if(countswipe>=0){
                flag=1;
            }
            else{
                flag=0;
                break;
            }

    }

}
if(flag==1)cout<<"YES\n";
else if(flar==0) cout<<"NO\n";

}
int main()
{
int t;
cin>>t;
while(t–)
{
solve();
}

return 0;

}
problem link:Access Control Practice Coding Problem - CodeChef

Hello friend,
You have to consider the first ‘0’ separately as the answer then is always NO.
And at any point if swipe value is negative, we make the flag false and break out of the loop.
This should solve the problem.

Have a great day.

Thanks Brother.I have a question that i have participated 23 div 4 Starters contest but i am not able to solve more than 2 question like (a,b).Can you give some idea how should i practice to solve c and d in contest .