Problem:
Swapping Characters

You are given a string and a number k. You are suggested to generate new strings by swapping any adjacent pair of characters in the string up to k times. Write a program to report the lexicographically smallest string among them.

Input

The input is given in the following format.

s
k

The first line provides a string s. The second line provides the maximum number of swapping operations k (0 ≤ k ≤ 109). The string consists solely of lower-case alphabetical letters and has a length between 1 and 2 × 105.

Output

Output the lexicographically smallest string.

Sample Input 1

pckoshien
3

Sample Output 1

ckopshien

Sample Input 2

pckoshien
10

Sample Output 2

cekophsin

Solution in JAVA (judge verdict: Time Limit Exceeded)

import java.io.IOException;
import java.util.Scanner;

class Main {
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		
		char[] s = sc.next().toCharArray();
		int k = sc.nextInt();
		
		int cur = 0;
		while(k > 0) {
			int place = cur;
			char min = s[cur];
			for(int i = cur + 1; i <= Math.min(cur + k, s.length - 1); i++) {
				if(min > s[i]) {
					min = s[i];
					place = i;
				}
			}
			
			for(int i = place - 1; i >= cur; i--) {
				s[i + 1] = s[i];
			}
			s[cur] = min;
			
			k -= place - cur;
			if(cur + 1 < s.length) {
				cur++;
			}else {
				break;
			}
		}
		
		System.out.println(String.valueOf(s));
	}
}