A9004 | Ilya and Two Numbers
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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.
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.
输入格式
The first line contains two integers $n,m$ $(1<=n,m<=10^{5},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.
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.
输出格式
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.
输入输出样例
输入 #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
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted