CF931C.Laboratory Work
普及+/提高
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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.
阿尼亚和基里尔正在做物理实验课作业。在其中一项任务中,他们需要对某个物理量测量 $ n $ 次,然后计算其平均值以减小误差。
基里尔已完成他的测量,得到了如下整数值:$ x_1, x_2, \dots, x_n $。值得注意的是,这些值彼此非常接近,即最大值与最小值之差至多为 $ 2 $。
阿尼亚不想亲自进行测量,但她又不能直接照抄基里尔的数据,因为每次测量的误差是随机的,这种完全一致的情况会被老师察觉。因此,阿尼亚希望在自己的作业中填写一组整数值 $ y_1, y_2, \dots, y_n $,使得满足以下条件:
- $ x_1, x_2, \dots, x_n $ 的平均值等于 $ y_1, y_2, \dots, y_n $ 的平均值;
- 阿尼亚的所有测量值均落在基里尔所有测量值的同一取值范围内,即阿尼亚数据中的最大值不超过基里尔数据中的最大值,且阿尼亚数据中的最小值不小于基里尔数据中的最小值;
- 在满足上述两个条件的前提下,阿尼亚与基里尔测量值中“相等的测量次数”应尽可能少。形式化地讲,老师会逐个检查阿尼亚的每个值;若在基里尔的数据中存在一个尚未被划去的相等值,则老师将划去该阿尼亚的值以及基里尔数据中一个对应的相等值。最终,“相等的测量次数”即为阿尼亚数据中被划去的值的总数。
请帮助阿尼亚构造出一组满足上述所有条件的测量值。
输入格式
The first line contains a single integer n (1 ≤ n ≤ 100 000) — the numeber of measurements made by Kirill.
The second line contains a sequence of integers _x_1, _x_2, ..., x__n ( - 100 000 ≤ x__i ≤ 100 000) — 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.
第一行包含一个整数 n(1≤n≤100000)—— Kirill 所做的测量次数。
第二行包含一个整数序列 x1,x2,…,xn(−100000≤xi≤100000)—— Kirill 所做的测量值。保证在所有值 x1,x2,…,xn 中,最大值与最小值之差不超过 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.
第一行输出相等测量值的最小可能数量。
第二行输出 n 个整数 y1, y2, …, yn —— Anya 应当填写的数值。这些整数可以以任意顺序输出。请注意:Anya 所填数值中的最小值不应小于 Kirill 数值中的最小值,且 Anya 所填数值中的最大值不应大于 Kirill 数值中的最大值。
若存在多个合法答案,输出其中任意一个即可。
输入输出样例
输入#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.
在第一个例子中,Anya 可以将零写为测量结果。此时平均值等于 Kirill 测量值的平均值,且仅有两个相等的测量值。
在第二个例子中,Anya 应写入两个值 100 和一个值 101(顺序任意),因为这是唯一能使平均值等于 Kirill 测量值平均值的方案。因此,全部三个测量值都相等。
在第三个例子中,相等的测量值个数为 5。
输入解题思路,AI测评打分。不知道怎么写?