➤ Problem Link : CRAN04
👉 Hint : edit please
✅ C++ Solution :
#include<bits/stdc++.h> using namespace std; #define ll long long int ll cum[1000001]; int main() { int t; cin>>t; while(t--) { ll ans=0; memset(cum,0,sizeof(cum)); ll n,k; string s; cin>>n>>k; scanf("\n"); getline(cin,s); ll l=s.length(); if(s[0]=='1') cum[0]=1; for(ll i=1;i<l;i++) cum[i]=cum[i-1]+s[i]-48; cum[-1]=0; for(ll i=0;i<l;i++) { ll left=lower_bound(cum+i,cum+l,cum[i-1]+k)-cum; ll right=upper_bound(cum+i,cum+l,cum[i-1]+k)-cum; ans+=right-left; } cout<<ans<<endl; } }
Thank you for your patience reading. If you enjoyed this post, I’d be very grateful if you’d help it spread by emailing it to a friend, or sharing it on Whatsapp or Facebook.
😇Happy Learning!!