A11635 | Laboratory Work
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Anya and Kirill are doing a physics laboratory work. In one of the tasks they have to measure some value $n$ times, and then compute the average value to lower the error.
Kirill has already made his measurements, and has got the following integer values: $x_{1}$ , $x_{2}$ , ..., $x_{n}$ . It is important that the values are close to each other, namely, the difference between the maximum value and the minimum value is at most $2$ .
Anya does not want to make the measurements, however, she can't just copy the values from Kirill's work, because the error of each measurement is a random value, and this coincidence will be noted by the teacher. Anya wants to write such integer values $y_{1}$ , $y_{2}$ , ..., $y_{n}$ in her work, that the following conditions are met:
- the average value of $x_{1},x_{2},...,x_{n}$ is equal to the average value of $y_{1},y_{2},...,y_{n}$ ;
- all Anya's measurements are in the same bounds as all Kirill's measurements, that is, the maximum value among Anya's values is not greater than the maximum value among Kirill's values, and the minimum value among Anya's values is not less than the minimum value among Kirill's values;
- the number of equal measurements in Anya's work and Kirill's work is as small as possible among options with the previous conditions met. Formally, the teacher goes through all Anya's values one by one, if there is equal value in Kirill's work and it is not strike off yet, he strikes off this Anya's value and one of equal values in Kirill's work. The number of equal measurements is then the total number of strike off values in Anya's work.
Help Anya to write such a set of measurements that the conditions above are met.
Kirill has already made his measurements, and has got the following integer values: $x_{1}$ , $x_{2}$ , ..., $x_{n}$ . It is important that the values are close to each other, namely, the difference between the maximum value and the minimum value is at most $2$ .
Anya does not want to make the measurements, however, she can't just copy the values from Kirill's work, because the error of each measurement is a random value, and this coincidence will be noted by the teacher. Anya wants to write such integer values $y_{1}$ , $y_{2}$ , ..., $y_{n}$ in her work, that the following conditions are met:
- the average value of $x_{1},x_{2},...,x_{n}$ is equal to the average value of $y_{1},y_{2},...,y_{n}$ ;
- all Anya's measurements are in the same bounds as all Kirill's measurements, that is, the maximum value among Anya's values is not greater than the maximum value among Kirill's values, and the minimum value among Anya's values is not less than the minimum value among Kirill's values;
- the number of equal measurements in Anya's work and Kirill's work is as small as possible among options with the previous conditions met. Formally, the teacher goes through all Anya's values one by one, if there is equal value in Kirill's work and it is not strike off yet, he strikes off this Anya's value and one of equal values in Kirill's work. The number of equal measurements is then the total number of strike off values in Anya's work.
Help Anya to write such a set of measurements that the conditions above are met.
输入格式
The first line contains a single integer $n$ ( $1<=n<=100000$ ) — the numeber of measurements made by Kirill.
The second line contains a sequence of integers $x_{1},x_{2},...,x_{n}$ ( $-100000<=x_{i}<=100000$ ) — the measurements made by Kirill. It is guaranteed that the difference between the maximum and minimum values among values $x_{1},x_{2},...,x_{n}$ does not exceed $2$ .
The second line contains a sequence of integers $x_{1},x_{2},...,x_{n}$ ( $-100000<=x_{i}<=100000$ ) — the measurements made by Kirill. It is guaranteed that the difference between the maximum and minimum values among values $x_{1},x_{2},...,x_{n}$ does not exceed $2$ .
输出格式
In the first line print the minimum possible number of equal measurements.
In the second line print $n$ integers $y_{1},y_{2},...,y_{n}$ — the values Anya should write. You can print the integers in arbitrary order. Keep in mind that the minimum value among Anya's values should be not less that the minimum among Kirill's values, and the maximum among Anya's values should be not greater than the maximum among Kirill's values.
If there are multiple answers, print any of them.
In the second line print $n$ integers $y_{1},y_{2},...,y_{n}$ — the values Anya should write. You can print the integers in arbitrary order. Keep in mind that the minimum value among Anya's values should be not less that the minimum among Kirill's values, and the maximum among Anya's values should be not greater than the maximum among Kirill's values.
If there are multiple answers, print any of them.
输入输出样例
输入 #1
6 -1 1 1 0 0 -1
输出 #1
2 0 0 0 0 0 0
输入 #2
3 100 100 101
输出 #2
3 101 100 100
输入 #3
7 -10 -9 -10 -8 -10 -9 -9
输出 #3
5 -10 -10 -9 -9 -9 -9 -9
In the first example Anya can write zeros as here measurements results. The average value is then equal to the average value of Kirill's values, and there are only two equal measurements.
In the second example Anya should write two values $100$ and one value $101$ (in any order), because it is the only possibility to make the average be the equal to the average of Kirill's values. Thus, all three measurements are equal.
In the third example the number of equal measurements is $5$ .
In the second example Anya should write two values $100$ and one value $101$ (in any order), because it is the only possibility to make the average be the equal to the average of Kirill's values. Thus, all three measurements are equal.
In the third example the number of equal measurements is $5$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted