CF313E.Ilya and Two Numbers
提高+/省选-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Ilya has recently taken up archaeology. He's recently found two numbers, written in the m-based notation. Each of the found numbers consisted of exactly n digits. Ilya immediately started looking for information about those numbers. He learned that the numbers are part of a cyphered code and the one who can decypher it can get the greatest treasure.
After considerable research Ilya understood that to decypher the code, he should do the following:
- Rearrange digits in the first number in some manner. Similarly, rearrange digits in the second number in some manner. As a result of this operation, the numbers can get leading zeroes.
- Add numbers, digit by digit, modulo m. In other words, we need to get the third number of length n, each digit of the number is the sum of the respective numbers of the found numbers. For example, suppose there are two numbers recorded in the ternary notation, 001210 and 012111, then if you add them to each other digit by digit modulo 3, you will get number 010021.
- The key to the code is the maximum possible number that can be obtained in the previous step.
Help Ilya, find the key to the code.
伊利亚最近开始从事考古学研究。他最近发现了两个以 m 进制表示的数字,每个数字恰好由 n 位数字组成。伊利亚立刻着手查找有关这两个数字的信息。他了解到,这两个数字是某种加密代码的一部分,而能够破译该代码的人将获得最珍贵的宝藏。
经过大量研究,伊利亚明白了破译该代码所需的操作步骤如下:
- 以某种方式重新排列第一个数字的各位数字;同样地,也以某种方式重新排列第二个数字的各位数字。经过此操作后,所得数字允许出现前导零。
- 将这两个数字按位相加(即对应位置上的数字相加),并对 m 取模。换言之,我们需要得到一个长度为 n 的第三位数字,其每一位均为原两个数字对应位数字之和对 m 取模的结果。例如,假设有两个三进制(即 m=3)数字:001210 和 012111,将它们按位相加并对 3 取模,得到的结果为 010021。
- 该代码的密钥即为上一步所能得到的最大可能数字。
请帮助伊利亚找出该代码的密钥。
输入格式
The first line contains two integers n, m (1 ≤ n, m ≤ 105, m > 1). The second line contains the first found number, the third line contains the second found number.
The numbers are recorded as a sequence of digits in the m-based notation. Each digit is an integer from 0 to m - 1. The digits in the line are written in the order from the most significant digits to the least significant ones.
The given numbers can contain leading zeroes.
第一行包含两个整数 n 和 m(1≤n,m≤105,且 m>1)。第二行包含第一个找到的数,第三行包含第二个找到的数。
这些数以 m 进制表示,记为一串数字序列。每个数字均为 0 到 m−1 之间的整数。每行中的数字按从最高位到最低位的顺序书写。
给定的数字可能包含前导零。
输出格式
Print n m-base digits. The resulting third number written in the m-based notation. Print the digits in the order from the most significant digits to the least significant ones.
输出 n 个 m 进制数字。结果为第三个数,以 m 进制表示。请按从最高位到最低位的顺序输出各位数字。
输入输出样例
输入#1
4 7 5 4 3 2 5 6 5 4
输出#1
6 4 2 1
输入#2
5 5 2 4 4 1 3 1 0 1 2 4
输出#2
4 4 4 3 2
输入解题思路,AI测评打分。不知道怎么写?