TZOJ 4493: Remove Digits

时间:2022-09-08 19:35:52

4493: Remove Digits TZOJ 4493: Remove Digits

时间限制(普通/Java):1000MS/3000MS     内存限制:65536KByte
总提交:
329
          
测试通过:77

描述

Given an N-digit number, you should remove K digits and make the new integer as large as possible.

输入

The first line has two integers N and K (1 ≤ K<N≤500000).
The next line has a N-digit number with no leading zero.

输出

Output the largest possible integers by removing K digits.

样例输入

4 2
2835

样例输出

85

 #include <bits/stdc++.h>
using namespace std;
char s[];
int main()
{
ios::sync_with_stdio(false);
int n,k,num=;
char c;
s[]='';
cin>>n>>k;
for(int i=;i<n;i++){
cin>>c;
while(c>s[num]){
if(!k||!num) break;
num--,k--;
}
s[++num]=c;
}
if(k)
num=num-k;
s[++num]='\0';
cout << s+ << endl;
return ;
}