#GD0000208. Pasha tối đa hóa (Pasha Maximizes)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Pasha tối đa hóa (Pasha Maximizes)
Pasha Maximizes
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
Pasha has a positive decimal integer without leading zeros. He wants to make its value as large as possible.
An operation swaps two adjacent decimal digits. He may perform at most operations, not necessarily using the entire allowance. Digits can move across multiple positions only by consecutive adjacent swaps.
Find the largest possible resulting integer.
Input
The only line contains two space-separated values: a positive decimal integer and a non-negative integer . The representation of has no leading zero.
Output
Print the decimal representation of the largest integer obtainable using at most adjacent swaps.
Subtasks
- Subtask 1 (20 points): ; ; is positive and has no leading zeros.
- Subtask 2 (30 points): ; ; is positive and has no leading zeros.
- Subtask 3 (50 points): ; ; is positive and has no leading zeros.
Examples
Input
1034 2
Output
3104
Explanation
Starting from 1034 with , swap the adjacent digits 0 and 3 to obtain 1304, then swap 1 and 3 to obtain 3104. Moving 4 to the first position would require three swaps, which is not allowed. Thus 3 is the best achievable leading digit and 3104 is the maximum.