Codeforces 931C Laboratory Work

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: x1, x2, ..., xn. 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 y1, y2, ..., yn in her work, that the following conditions are met:

  • the average value of x1, x2, ..., xn is equal to the average value of y1, y2, ..., yn;
  • 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.

Input

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 x1, x2, ..., xn ( - 100 000 ≤ xi ≤ 100 000) — the measurements made by Kirill. It is guaranteed that the difference between the maximum and minimum values among values x1, x2, ..., xn does not exceed 2.

Output

In the first line print the minimum possible number of equal measurements.

In the second line print n integers y1, y2, ..., yn — 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.

Examples
Input
6
-1 1 1 0 0 -1
Output
2
0 0 0 0 0 0 
Input
3
100 100 101
Output
3
101 100 100 
Input
7
-10 -9 -10 -8 -10 -9 -9
Output
5
-10 -10 -9 -9 -9 -9 -9 
Note

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.


昨天因为一些私事没能打这个比赛,不然估计得涨分了。但也涨不了多少,因为快到深蓝了,所以打比赛也需要更高层次的水平,对于我这种菜鸡,还需要更加好好努力。虽然我很菜,但是我没有放弃前进的希望。

今天能把这道题给AC,有点小开心,WA了一发,被第三个样例坑了一下。稍后会讲被坑的点。


题意:

  Anya想偷(借)一下Kirill的物理实验数据(跟我一样,我也喜欢这样做), Kirill的数据最大值和最小值差小于等于2.


因为老师会检查两个人的实验数据,看看两个相同的数据有多少?


Anya想相同数据最少,然后自己的最大值不大于他的数据的最大值,自己的最小值不小于他数据的最小值


如果存在多组答案的话,输出其中一个就行了。

解题思路:


首先一看到这个题,我就有点头疼,不想看,还不如D题看得舒服,然后我就先A了D再回来做这道题,。

虽然心里有点小抗拒,但是为了自己的成长,还是可以忍受忍受的。(不说些废话了)


这个题目说了最大值和最小值之差小于等于2,这个条件把这道题变简单了,不然我顿时没有头绪。

然后我是根据这个条件入手的。

一开始的时候,我是想把n个元素全部累加后求平均值的,但是边写边想的时候发现,没这个必要,先找到最大值和最小值,然后遍历桶排,这时候我们就能知道有多少个元素是最小值,多少个元素是在最小值和最大值之间,多少个元素是最大值。

如果最大值减去最小值是小于等于1的 那么直接输出就行(不懂得看第二组样例提示)


如果最大值减去最小值是等于2的话 那么 就来了。

你为了让相同的数量值最小,那么是不是你需要进行一些操作,使得这个值最小



回到最初  题目给的条件

假设 最小值为a ,中间值为b ,最大值为c

k1 表示a个个数 k2表示b的个数  k3表示c的个数

那么我们可以拿 一个a和一个c 换两个b 这样的操作有x次

那么相同的数量就变成了n-2*x

然后输出变化完 k1'个最小值 k2'个中间值 k3'个最大值。

我就是这样想的,而且满足全部样例

可是 结果WA了

这让我百思不得其姐, 有点头疼。

当我想拿这个题调戏一下不会的XX同志的时候,然后我就想到了 我之前没有想到的一个点

那就是



    如果你可以拿1个a和1个c换2个b 那你能不能拿2个b换1个a和1个c

对,就是这样,没想到吧。我也一样。(在此多谢XX同志)。

你把两组答案存下来,哪个相同的最小就输出哪个

附上AC代码

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
const int maxn=1e5+10;
int n,num[4],arr[maxn],ans1[4],ans2[4];
int main(){
	int i,j;
	scanf("%d",&n);
	int mi=maxn,ma=-maxn;
	for(i=1;i<=n;i++){
		scanf("%d",&arr[i]);
		if(arr[i]<mi) mi=arr[i];
		if(arr[i]>ma) ma=arr[i];
	}
	memset(num,0,sizeof(num));
	for(i=1;i<=n;i++){
		int t=arr[i]-mi+1;
		num[t]++;
	}
	if(ma-mi+1<3){
		printf("%d\n",n);
		printf("%d",mi);
		num[1]--;
		while(num[1]){
			printf(" %d",mi);
			num[1]--;
		}
		while(num[2]){
			printf(" %d",mi+1);
			num[2]--;
		}
	}
	else{
		memset(ans1,0,sizeof(ans1));
		memset(ans2,0,sizeof(ans2));
		int te=min(num[1],num[3]);
		ans1[1]=num[1]-te;
		ans1[2]=num[2]+2*te;
		ans1[3]=num[3]-te;
		ans1[0]=n-te*2;
		te=num[2]/2;
		ans2[1]=num[1]+te;
		ans2[2]=num[2]-2*te;
		ans2[3]=num[3]+te;
		ans2[0]=n-te*2;
		if(ans1[0]<=ans2[0]){
			printf("%d\n",ans1[0]);
			int flag=0;
			for(i=1;i<=3;i++){
				while(ans1[i]){
					if(flag)
						printf(" ");
					printf("%d",mi+i-1);
					flag=1;
					ans1[i]--;
				}
			}
			printf("\n");
		}
		else{
			printf("%d\n",ans2[0]);
			int flag=0;
			for(i=1;i<=3;i++){
				while(ans2[i]){
					if(flag)
						printf(" ");
					printf("%d",mi+i-1);
					flag=1;
					ans2[i]--;
				}
			}
			printf("\n");
		}
	}
	return 0;
}

欢迎各位大佬前来指正探讨。
一起加油!!!





  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值