304804: CF915C. Permute Digits
Memory Limit:256 MB
Time Limit:1 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
Permute Digits
题意翻译
给出两个正整数a,b。在十进制下重排a,构造一个不超过b的最大数,不能有前导零。允许不去重排a。 输入格式: 第一行一个数a ($1\le a\le 10^{18}$)。第二行一个数b ($1\le b\le 10^{18}$) 数没有前导零,数据保证有解。 输出格式: 输出一个数,表示a重排后不超过b的最大数,不应该有前导零。 输出的数的长度应该与a相等,它应该是a的一个排列。题目描述
You are given two positive integer numbers $ a $ and $ b $ . Permute (change order) of the digits of $ a $ to construct maximal number not exceeding $ b $ . No number in input and/or output can start with the digit 0. It is allowed to leave $ a $ as it is.输入输出格式
输入格式
The first line contains integer $ a $ ( $ 1<=a<=10^{18} $ ). The second line contains integer $ b $ ( $ 1<=b<=10^{18} $ ). Numbers don't have leading zeroes. It is guaranteed that answer exists.
输出格式
Print the maximum possible number that is a permutation of digits of $ a $ and is not greater than $ b $ . The answer can't have any leading zeroes. It is guaranteed that the answer exists. The number in the output should have exactly the same length as number $ a $ . It should be a permutation of digits of $ a $ .
输入输出样例
输入样例 #1
123
222
输出样例 #1
213
输入样例 #2
3921
10000
输出样例 #2
9321
输入样例 #3
4940
5000
输出样例 #3
4940