Here’s my thought :
#include <bits/stdc++.h>
#define vi vector<int>
using namespace std;
void setIO() {
cin.tie(0)->ios_base::sync_with_stdio(0);
}
void solve() {
int n,k;
cin >> n >> k;
string s;
cin >> s;
cout << 1;
vi pz(n+1), po(n+1);
for(int i = 1;i <= n;++i) {
if(s[i-1] == '0') {
pz[i] = pz[i-1] + 1;
po[i] = po[i-1];
}
else {
pz[i] = pz[i-1];
po[i] = po[i-1] + 1;
}
}/*
for(auto &x : pz) cout << x << ' ';
cout << '\n';
for(auto &x : po) cout << x << ' ';*/
int t = 0;
for(int i = 2;i <= n;++i) {
if(abs(po[i]-pz[i])-t > k) {
t = abs(po[i-1]-pz[i-1]);
cout << 1;
}
else {
cout << 0;
}
}
cout << '\n';
}
int main() {
setIO();
int t;
cin >> t;
while(t--) solve();
return 0;
}
& here’s my submission:
I know I m stuck due to that temporary variable t but don’t get what’s exactly being wrong here or how can I fix it