304901: CF931C. Laboratory Work

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Laboratory Work

题意翻译

### 题目描述 $Anya$ 和 $Kirill$ 正在做一个物理实验,他们必须测量一些值 $n$ 次,然后求出平均值以降低误差。 $Kirill$ 已经完成了测量,得到了 $n$ 个数据:$x_1,x_2,\dots,x_n$。这些值非常接近,其中的最大值与最小值之差不超过 $2$。 $Anya$ 不想去测量,但是他也不能直接抄 $Kirill$ 的数据,因为每次测量的误差是随机的,如果直接抄的话会被老师发现。$Anya$ 想要得到一组数据 $y_1,y_2,\dots,y_n$ ,这组数据满足如下条件: * $x_1,x_2,\dots,x_n$ 的平均值要等于 $y_1,y_2,\dots,y_n$ 的平均值。 * $\max(y_1,y_2,\dots,y_n) \le \max(x_1,x_2,\dots,x_n)$ 并且 $\min(y_1,y_2,\dots,y_n) \ge \min(x_1,x_2,\dots,x_n)$。 * 两组数据中相等的数尽可能少,即你造的数据中尽量不要出现 $Kirill$ 的数据中出现过的数。 找出这样的一组测量值。 ### 输入格式 第一行有一个整数 $n \ (1 \le n \le 100000)$,所需数据的个数。 第二行 $n$ 个整数 $x_1,x_2,\dots,x_n \ (-100000 \le x_i \le 100000)$,表示 $Kirill$ 的测量值,保证其中的最大值与最小值之差不超过 $2$。 ### 输出格式 第一行输出 $Anya$ 的测量值与 $Kirill$ 的测量值中最少的相同的个数。 输出你造的 $y_1,y_2,\dots,y_n$。要满足题目中的条件。 多种可能只需要输出一种。 ### 说明/提示 [数据范围] $1 \le n \le 100000$。 $-100000 \le x_i \le 100000$ [样例解释] 第一个样例中,$0,0,0,0,0,0$ 与 $-1,1,1,0,0,-1$ 的平均值相等,只有两个相等的 $0$。 第二个样例中,要想使平均值相等,$Anya$ 的测量值只能与 $Kirill$ 的测量值相等。 第三个样例中,最少也要有 $5$ 个相等的数。 translated by [yu__xuan](https://www.luogu.com.cn/user/142110).

题目描述

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.

输入输出格式

输入格式


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 $ .

输出格式


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.

输入输出样例

输入样例 #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 $ .

Input

题意翻译

### 题目描述 $Anya$ 和 $Kirill$ 正在做一个物理实验,他们必须测量一些值 $n$ 次,然后求出平均值以降低误差。 $Kirill$ 已经完成了测量,得到了 $n$ 个数据:$x_1,x_2,\dots,x_n$。这些值非常接近,其中的最大值与最小值之差不超过 $2$。 $Anya$ 不想去测量,但是他也不能直接抄 $Kirill$ 的数据,因为每次测量的误差是随机的,如果直接抄的话会被老师发现。$Anya$ 想要得到一组数据 $y_1,y_2,\dots,y_n$ ,这组数据满足如下条件: * $x_1,x_2,\dots,x_n$ 的平均值要等于 $y_1,y_2,\dots,y_n$ 的平均值。 * $\max(y_1,y_2,\dots,y_n) \le \max(x_1,x_2,\dots,x_n)$ 并且 $\min(y_1,y_2,\dots,y_n) \ge \min(x_1,x_2,\dots,x_n)$。 * 两组数据中相等的数尽可能少,即你造的数据中尽量不要出现 $Kirill$ 的数据中出现过的数。 找出这样的一组测量值。 ### 输入格式 第一行有一个整数 $n \ (1 \le n \le 100000)$,所需数据的个数。 第二行 $n$ 个整数 $x_1,x_2,\dots,x_n \ (-100000 \le x_i \le 100000)$,表示 $Kirill$ 的测量值,保证其中的最大值与最小值之差不超过 $2$。 ### 输出格式 第一行输出 $Anya$ 的测量值与 $Kirill$ 的测量值中最少的相同的个数。 输出你造的 $y_1,y_2,\dots,y_n$。要满足题目中的条件。 多种可能只需要输出一种。 ### 说明/提示 [数据范围] $1 \le n \le 100000$。 $-100000 \le x_i \le 100000$ [样例解释] 第一个样例中,$0,0,0,0,0,0$ 与 $-1,1,1,0,0,-1$ 的平均值相等,只有两个相等的 $0$。 第二个样例中,要想使平均值相等,$Anya$ 的测量值只能与 $Kirill$ 的测量值相等。 第三个样例中,最少也要有 $5$ 个相等的数。 translated by [yu__xuan](https://www.luogu.com.cn/user/142110).

加入题单

上一题 下一题 算法标签: