296. Sasha vs. Kate
Memory limit: 65536 kilobytes
output: standard
During the regular Mars's World Finals Subregional Programming Contest a boy Sasha lost N "Mars" bars of chocolate to a girl Kate. But for two years already Sasha does not hurry to pay his debt. And now Sasha and Kate decided that Sasha will give Kate P chocolate bars, where number P can be obtained from the number N by removing exactly K decimal digits. Sasha generously let Kate to choose digits to be removed. Your task is to find out how many bars Sasha will give Kate. Of course Kate will choose K digits from the number N in such a way that the resulting number P would be maximal.
sample input | sample output |
1992 2 | 99 |
sample input | sample output |
1000 2 | 10 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
char s[1005];
int k;
int main()
{
scanf("%s %d",s,&k);
int len=strlen(s);
int w=len-k;
int index=-1;
while(w)
{
char mx='0';
for(int i=index+1;i<=index+1+k;i++)mx=max(mx,s[i]);
for(int i=index+1;i<=index+1+k;i++)
{
if(s[i]==mx)
{
printf("%c",s[i]);
w--;
k-=(i-index-1);
index=i;
break;
}
}
}
return 0;
}