https://www.luogu.com.cn/problem/P1106
这 * 的 *贪心模拟搞我两小时吐了555555555~
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
string s;
int k,tmp,ans[300],cnt,minn,first0,head;
int main(){
cin>>s>>k;
int w=k;
while(first0<k){
//cout<<first0<<" "<<k<<endl;
k-=first0;
head+=first0;
while(s[head]-'0'==0) head++;
first0=0;
for(int i=head;i<s.size();i++){
if(s[i]-'0'==0){
first0=i-head;
//cout<<first0<<endl;
break;
}
}
if(first0==0) break;
}
//cout<<k<<" ";
first0=0;
for(int i=head;i<s.size();i++){
if(s[i]-'0'==0){
first0=i-head+1;
break;
}
}
// first0>k正常做
//cout<<head<<" "<<first0<<" ";
if(first0==k){
int flag=0;
for(int i=k;i<s.size();i++){
if(s[i]-'0') flag=1;
if(flag) cout<<s[i]-'0';
}
return 0;
}
int finished=0;
for(int i=head;i<=s.size()-1;i++){
//cout<<k<<endl;
if(s.size()-w==cnt) break;
if(!k){
for(int j=i;j<=s.size()-1;j++) ans[++cnt]=s[j]-'0';
finished=1;
}
if(finished) break;
minn=0x3f3f3f3f;
for(int j=i;j<=s.size()-1&&j<=i+k;j++){
if(s[j]-'0'<minn){
minn=s[j]-'0';
tmp=j;
}
}
//cout<<tmp<<" ";
k-=(tmp-i);
//cout<<k<<" ";
ans[++cnt]=minn;
i=tmp;
//cout<<i<<endl;
}
//cout<<cnt<<endl;
for(int i=1;i<=cnt;i++) cout<<ans[i];
return 0;
}