#P11100. [ROI 2022] 交换 (Day 2)
[ROI 2022] 交换 (Day 2)
Background
Translated from ROI 2022 D2T1。
You are given an -digit decimal number 。You may swap two adjacent digits any number of times, and each swap costs 。If after such swaps you obtain the number , then the profit equals 。
Definition: if by swapping you obtain a number from , and during this process you achieve the maximum possible profit, then is called an optimal number。
For example, when , you can move the digit in to the front by swapping times, obtaining the maximum profit 。In this case, is called an optimal number。
Problem Description
As is well known, such optimal numbers may be more than one (for the same , all its optimal numbers have the same profit, but their values are different)。Given and , you need to determine the maximum value among all optimal numbers。
Input Format
The first line contains an integer consisting of decimal digits ()。The number may have leading zeros。
The second line contains an integer , the cost of one swap ()。
Output Format
Output an integer , the maximum among all optimal numbers。The length of is , and it may contain leading zeros。
170
15
710
170
600
170
314599
17713
931459
001
1000
001
3327
114
7332
Hint
| Subtask | Score | Special property | ||
|---|---|---|---|---|
consists of 1 or 2 |
||||
Translated by ChatGPT 5