MAXVAC - Editorial

Blockquote
Can any one tell where my code fails ?

#include <bits/stdc++.h>

using namespace std;

void solve(){
	int n,x;
	string str;
	cin >> n >> x;
	cin >> str;
	vector<int> v,diff;
	int pos = 0;
	for(auto x: str){
		if(x == '1')v.push_back(pos);
		pos++;
	}
	int ans = 0,len = v.size();
	if(len != 0){
		ans += (v[0]/x);
		diff.push_back(v[0] % x);
		for(auto it = 0;it < len - 1;++it){
			int temp = (abs(v[it] - v[it+1]) - 1)%x;
			ans += (abs(v[it] - v[it+1]) - 1)/x;
			diff.push_back(temp);
		}
		ans += (n - v[len-1]-1)/x;
		diff.push_back((n - v[len - 1] - 1)%x);
		if(diff.size() == 1 && diff[0] == x - 1)ans++;
		else{
			int l = diff.size();
			for(int i = 0;i<l - 1;++i){
				if(diff[i] + diff[i + 1] == x - 1){
					ans++;
					break;
				}
			}
		}
	}
	else ans = (n/x);
	cout << ans << "\n";
	
}

int main(){
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL);
	int64_t test;
	cin >> test;
	while(test--){
		solve();
	}
}