Minimization by Swaps

시간 제한2초메모리 제한2048 MB

요약
숫자 문자열과 인접 교환 횟수 k가 주어질 때, k번 이하의 교환으로 만들 수 있는 가장 작은 수를 구한다.
난이도

보통10점 중 6점

유형
그리디, 문자열, 완전 탐색, 구현
정답자
아직 제출이 없습니다

문제

Masha is studying large numbers. She has placed nn cards in a row. Each card has a digit from 11 to 99 written on it. Together, they form an nn-digit integer ss.

In one operation, Masha can take two adjacent cards and swap them (she cannot rotate the cards, turning one digit into another). Masha can perform no more than kk operations. What is the minimum nn-digit number that can be obtained as a result?

입력

The first line contains an integer tt: the number of test cases (1≤t≤100,0001 \le t \le 100\\,000). The following lines contain the test cases.

Each test case is given on a line containing two integers ss and kk separated by a space. The integer ss is positive and consists of digits from 11 to 99. Additionally, 0≤k≤10180 \le k \le 10^{18}.

The total number of digits in all numbers ss does not exceed 100,000100\\,000.

출력

For each test case, print a line with the answer: the minimum nn-digit number that can be obtained from ss by swapping two adjacent digits no more than kk times.

예제1

  1. 예제 1

    입력
    4
    321 0
    9 1
    21241127 10
    692 1
    
    예상 출력
    321
    9
    11122247
    629