My issue
please help me
My code
#include <bits/stdc++.h>
using namespace std;
void solve(){
int n,k;
cin>>n>>k;
string f,s;
cin>>f>>s;
vector<int>prev(n);
for(int i=0;i<n;i++){
prev[i]=i;
if(i and s[i]==s[i-1]) prev[i]=prev[i-1];
}
vector<pair<int,char>>changes;
int j=n;
int pos_=n;
char c_;
for(int i=0;i<k;i++){
j--;
if(j-k+1<0) break;
if(j>=pos_) f[j]=c_;
if(s[j]==f[j]) continue;
f[j]=s[j];
pos_=j-k+1,c_=f[j];
changes.push_back({pos_,c_});
}
while(--j>=pos_) f[j]=c_;
bool change[n]={false};
char c;
int pos=-1;
for(int i=0;i<n;i++){
char &curr=f[i];
if(pos>=i) curr=c;
if(curr==s[i]) continue;
int p=prev[i];
p=max(p,i-k+1);
if(p+k-1>=n) continue;
if(!change[p]) changes.push_back({p,s[i]});
change[p]=true;
pos=p+k-1,c=s[i];
f[i]=s[i];
}
if(f!=s) cout<<-1<<endl;
else{
cout<<changes.size()<<endl;
for(auto t:changes) cout<<t.first+1<<" "<<t.second<<endl;
}
}
int main() {
int t;
cin>>t;
while(t--) solve();
}
Problem Link: Replacing Game Practice Coding Problem