Pasha Maximizes

B. Pasha Maximizes
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Pasha has a positive integer a without leading zeroes. Today he decided that the number is too small and he should make it larger. Unfortunately, the only operation Pasha can do is to swap two adjacent decimal digits of the integer.

Help Pasha count the maximum number he can get if he has the time to make at most k swaps.

Input

The single line contains two integers a and k (1 ≤ a ≤ 1018; 0 ≤ k ≤ 100).

Output

Print the maximum number that Pasha can get if he makes at most k swaps.

输入输出样例

输入 #1
1990 1
输出 #1
9190
输入 #2
300 0
输出 #2
300
输入 #3
1034 2
输出 #3
3104
输入 #4
9090000078001234 6
输出 #4
9907000008001234
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
string s;
int res,n,num,cnt,i;
int main()
{
    cin>>s>>n;
    num=n;
    while(num>0){
        while(s[cnt]=='9'&&cnt<=s.size()) ++cnt;
        int maxx=cnt;
        if(cnt>=s.size()) break;
        for(i=cnt+1;i<=num+cnt&&i<s.size();i++) if(s[maxx]<s[i]) maxx=i;
        if(maxx==cnt){//如果后面没有比它大的了,那就找下一位
            cnt++;
            continue;
        }
        for(i=cnt+1;i<=maxx;i++) swap(s[cnt],s[i]),num--;//每一步都要交换
    }
    cout<<s<<endl;
    return 0;
}

 

posted @ 2023-06-12 13:53  o-Sakurajimamai-o  阅读(18)  评论(0)    收藏  举报
-- --