题干:

Eugeny has n cards, each of them has exactly one integer written on it. Eugeny wants to exchange some cards with Nikolay so that the number of even integers on his cards would equal the number of odd integers, and that all these numbers would be distinct.

Nikolay has m cards, distinct numbers from 1 to m are written on them, one per card. It means that Nikolay has exactly one card with number 1, exactly one card with number 2 and so on.

A single exchange is a process in which Eugeny gives one card to Nikolay and takes another one from those Nikolay has. Your task is to find the minimum number of card exchanges and determine which cards Eugeny should exchange.

Input

The first line contains two integers n and m (2 ≤ n ≤ 2·105, 1 ≤ m ≤ 109) — the number of cards Eugeny has and the number of cards Nikolay has. It is guaranteed that n is even.

The second line contains a sequence of n positive integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the numbers on Eugeny's cards.

Output

If there is no answer, print -1.

Otherwise, in the first line print the minimum number of exchanges. In the second line print n integers — Eugeny's cards after all the exchanges with Nikolay. The order of cards should coincide with the card's order in the input data. If the i-th card wasn't exchanged then the i-th number should coincide with the number from the input data. Otherwise, it is considered that this card was exchanged, and the i-th number should be equal to the number on the card it was exchanged to.

If there are multiple answers, it is allowed to print any of them.

Examples

Input

6 2
5 6 7 9 4 5

Output

1
5 6 7 9 4 2

Input

8 6
7 7 7 7 8 8 8 8

Output

6
7 2 4 6 8 1 3 5

Input

4 1
4 2 1 10

Output

-1

题目大意:

尤金有 n 张卡片。每张卡片上都有一个整数。 尤金希望与尼古拉交换一些卡片,使得他的偶数卡片上的数量等于奇数卡片的数量,并且所有这些数字不同的。

尼古拉有 m 张卡,上面的数字为 1 到 m ,也就是每种数字的卡各一张。

每次两人可以交换一张卡,问最少交换几次可以满足尤金的要求。

Input

第一行包含两个整数 n 和 m (2 ≤ n ≤ 2·105, 1 ≤ m ≤ 109) — 分别表示两人拥有的卡片数。 保证 n 是偶数。

第二行包含一个由 n 个正整数组成的数列 a1, a2, ..., an (1 ≤ ai ≤ 109) — 表示尤金的卡。

Output

如果没有答案,输出 -1.

否则,在第一行输出最小需要换的卡片数。在第二行输出 n 个整数 — 交换后尤金的卡牌。 卡牌的顺序要和读入时一样,如果有多种方案,输出任意一种。

解题报告:

先预处理出来在<=m的前提下有多少奇数和偶数可以使用,然后先保证能不变的先不变(打个ok标记),剩下的贪心填。注意一下贪心的顺序,并且时刻注意填的数要<=m这个限制就好。

注意一定要先保证能不变的就不变,不然的话你不确定后面已经有多少奇数偶数了,那么就不能确定这一位优先填奇数还是偶数,所有有可能操作次数不是最少的。

AC代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#define FF first
#define SS second
#define ll long long
#define pb push_back
#define pm make_pair
using namespace std;
typedef pair<int,int> PII;
const int MAX = 6e5 + 5;
ll n,m,ji,ou,resji,resou,needji,needou;
ll a[MAX];
set<ll> sji,sou,ans;
bool vis[MAX],ok[MAX];
vector<int> o,j;
int main()
{cin>>n>>m;if(m&1) resou=m/2,resji=resou+1;else resou=resji=m/2;for(int i = 1; i<=n; i++) { scanf("%lld",a+i);if(a[i] < MAX) vis[a[i]]=1;if(a[i]&1) {ji++;if(a[i] <= m && sji.find(a[i]) == sji.end()) resji--;sji.insert(a[i]);}else {ou++;if(a[i] <= m && sou.find(a[i]) == sou.end()) resou--;sou.insert(a[i]);}}ll bij = n/2-sji.size();//必须要去掉的奇数,准确的说,是还需要换上的奇数,还缺少的奇数ll bio = n/2-sou.size();//必须要去掉的偶数if(resji < bij || resou < bio) return 0,puts("-1");ll tmp = max(bij,0LL)+max(bio,0LL);printf("%lld\n",tmp);for(int i = 2; i<=min(m,1LL*MAX-1); i+=2) {if(vis[i]) continue;o.pb(i);}for(int i = 1; i<=min(m,1LL*MAX-1); i+=2) {if(vis[i]) continue;j.pb(i);}ll curji=0,curou=0;for(int i = 1; i<=n; i++) {if(ans.count(a[i])) continue;ans.insert(a[i]);if((a[i]&1) && curji < n/2) curji++,ok[i]=1;else if((a[i]&1)==0 && curou<n/2)curou++,ok[i]=1;}for(int i = 1; i<=n; i++) {if(ok[i]) {continue;}if(a[i]&1) {//如果是奇数if(ans.count(a[i])) {if(curji < n/2) a[i]=j.back(),j.pop_back(),curji++;else if(curou < n/2) a[i] = o.back(),o.pop_back(),curou++;}else {if(curji < n/2) ans.insert(a[i]),curji++;else a[i] = o.back(),o.pop_back(),curou++;}}else {if(ans.count(a[i])) {if(curji < n/2) a[i]=j.back(),j.pop_back(),curji++;else if(curou < n/2) a[i] = o.back(),o.pop_back(),curou++;}else {if(curou < n/2) ans.insert(a[i]),curou++;else a[i] = j.back(),j.pop_back(),curji++;}}}for(int i = 1; i<=n; i++) printf("%lld ",a[i]);return 0 ;
}

【CodeForces - 746E】Numbers Exchange(贪心构造)相关推荐

  1. CodeForces - 1265D Beautiful Sequence(贪心+构造+思维)

    题目链接:点击查看 题目大意:给出a个0,b个1,c个2,d个3,要求构造一种序列,使得数列两两之间绝对值之差等于1,若不能构造输出NO 题目分析:首先我们需要稍微讨论一下特殊情况,那就是对于两端的数 ...

  2. CodeForces - 1256C Platforms Jumping(贪心+构造)

    题目链接:点击查看 题目大意:现在固定人初始时在点0处,现在我们需要跨过长度为n的一条河,到达对岸的点n+1处,给出m个木板,我们可以将这m个木板随意摆放,但相对位置不能改变,并且只能互相接触而不能互 ...

  3. CodeForces - 1255D Feeding Chicken(贪心+构造+模拟)

    题目链接:点击查看 题目大意:给出一个n*m的农场,其中'.'代表空地,'R'代表大米,现在有k只鸡需要分布在这个农场之中,需要满足以下条件: 每个方格都要被鸡占领 每只鸡至少占领一个方格 每只鸡占领 ...

  4. 贪心+构造 Codeforces Round #277 (Div. 2) C. Palindrome Transformation

    题目传送门 1 /* 2 贪心+构造:因为是对称的,可以全都左一半考虑,过程很简单,但是能想到就很难了 3 */ 4 /**************************************** ...

  5. 2021年度训练联盟热身训练赛第五场 H题In-place Sorting+贪心构造

    题意: 给你n个小于101810^{18}1018的大数,问在可以再不改变序列位置,之改变数值中某数位的'9'变为'6'或将'6'变为'9',求的最终序列由小到大,且字典序最小. 题目: 链接:htt ...

  6. 【牛客 - 318G】LLLYYY的数字思维 与【牛客 - 289J】这是一个沙雕题II(贪心构造)

    题干: LLLYYY很喜欢写暴力模拟贪心思维.某一天在机房,他突然抛给了队友ppq一 个问题.问题如下: 有一个函数f (): int f(int x){     int tmp = 0;     w ...

  7. 常规贪心构造题 最多能完成排序的块 II

    这是 LeetCode 上的  最多能完成排序的块 II ,难度为 困难. Tag : 「贪心」 这个问题和"最多能完成排序的块"相似,但给定数组中的元素可以重复,输入数组最大长度 ...

  8. codeforces Gym 100338E Numbers (贪心,实现)

    题目:http://codeforces.com/gym/100338/attachments 贪心,每次枚举10的i次幂,除k后取余数r在用k-r补在10的幂上作为候选答案. #include< ...

  9. CodeForces - 1494D Dogeforces(贪心+构造)

    题目链接:点击查看 题目大意:给出 nnn 个叶子结点和一个 n∗nn*nn∗n 的 LCALCALCA 矩阵,其中 LCALCALCA 表示的是最近公共祖先节点的权值,现在需要构造出一棵自顶向下权值 ...

最新文章

  1. python代码编写规范_python初学者-代码规范
  2. RDKit | 基于RDKit(≥2020.09.1)的相似图绘制新方法
  3. Spartan-6系列内部模块介绍之可配置逻辑模块(CLB)
  4. php 实验室管理系统,生物信息实验室管理系统-Metalims安装
  5. 根据图片URL获取图片的尺寸【Swift语言实现】
  6. 停航63天!湖北复航了,机票预订火爆程度堪比春运
  7. java图像在背景图移动_java – 在Swing中移动背景图像
  8. 【实用工具】之VMware workstation 14中安装CentOS 7
  9. (转)C# Enum,Int,String的互相转换 枚举转换
  10. Java Web 高性能开发,第 1 部分: 前端的高性能
  11. 学生选课系统代码-1start.py代码
  12. yum源中repodata目录下的各文件内容及作用-转载
  13. Linux vim编辑器简单使用之二:vim操作快捷键、小技巧
  14. 产品经理懂点技术之:大话5G
  15. mysql删表重来_BeetlSQL自定义NameConversion去除Pojo和表前缀
  16. HttpClient 4 和 HttpClient 3 设置超时
  17. TCP/IP常见英文缩写
  18. 【NLP基础理论】10 上下文表示(Contextual Representation)
  19. 店铺DRS评分这样来做|盛天海电商
  20. 华为H3CNE认证题库、教材-热门下载帖汇总!

热门文章

  1. 第一步:Axure 使用svn多人协作产品开发(提交文件)
  2. [Leetcode][第120题][JAVA][三角形最小路径和][动态规划][递归]
  3. 环形队列出队的元素怎么输出出来_队列的知识讲解与基本实现(数据结构)
  4. vue点击切换类名_vue 新用户引导(vue-dirver)
  5. linux ubantu扩展空间,ubuntu 扩展存储空间
  6. java报错空指针异常_夯实基础:认识一下这10 个深恶痛绝的 Java 异常
  7. python将整数逆序_python练手入门小项目:字符串的妙用
  8. 重燃你的PHP安全之火.pdf,读《重燃你的php之火》总结笔记
  9. 哲学家就餐问题python_Python实现哲学家就餐问题实例代码
  10. asterisk extconfig.conf文件解析