Problem description

One day Ms Swan bought an orange in a shop. The orange consisted of n·k segments, numbered with integers from 1 to n·k.

There were k children waiting for Ms Swan at home. The children have recently learned about the orange and they decided to divide it between them. For that each child took a piece of paper and wrote the number of the segment that he would like to get: the i-th (1 ≤ i ≤ k) child wrote the number ai (1 ≤ ai ≤ n·k). All numbers ai accidentally turned out to be different.

Now the children wonder, how to divide the orange so as to meet these conditions:

  • each child gets exactly n orange segments;
  • the i-th child gets the segment with number ai for sure;
  • no segment goes to two children simultaneously.

Help the children, divide the orange and fulfill the requirements, described above.

Input

The first line contains two integers nk (1 ≤ n, k ≤ 30). The second line contains kspace-separated integers a1, a2, ..., ak (1 ≤ ai ≤ n·k), where ai is the number of the orange segment that the i-th child would like to get.

It is guaranteed that all numbers ai are distinct.

Output

Print exactly n·k distinct integers. The first n integers represent the indexes of the segments the first child will get, the second n integers represent the indexes of the segments the second child will get, and so on. Separate the printed numbers with whitespaces.

You can print a child's segment indexes in any order. It is guaranteed that the answer always exists. If there are multiple correct answers, print any of them.

Examples

Input

2 2
4 1

Output

2 4 
1 3

Input

3 1
2

Output

3 2 1 
解题思路:这道题看辣么久才看懂,真的是怀疑自己的智商QAQ。输出有k行,每行必须包含一个儿童想要的那块橙子块编号(该行的任意位置输出都可以),再输出n-1个橙子块的编号,编号不能有重复输出,[1,n*k]中每个编号只输出1次即可。
AC代码:
 #include<bits/stdc++.h>
using namespace std;
int main(){
int n,k,cnt=,a[],b[];
cin>>n>>k;
for(int i=;i<=n*k;++i)a[i]=i;
for(int i=;i<=k;++i){cin>>b[i];a[b[i]]=;}
for(int i=;i<=k;++i){
cout<<b[i];//每一行先输出b[i]
int t=;//t为计数器,一行输出n个数
while(t<n){
if(a[cnt]){cout<<' '<<a[cnt++];t++;}
else cnt++;
}
cout<<endl;
}
return ;
}

E - Dividing Orange的更多相关文章

  1. Codeforces Round #150 (Div. 2)

    A. Dividing Orange 模拟. B. Undoubtedly Lucky Numbers 暴力枚举\(x.y\). C. The Brand New Function 固定左端点,右端点 ...

  2. 利用Python【Orange】结合DNA序列进行人种预测

    http://blog.csdn.net/jj12345jj198999/article/details/8951120 coursera上 web intelligence and big data ...

  3. orange pi pc 体验(一)

    最近在淘宝上看到一款和树莓派差不多的卡片机,定价才99元,而且是国产的,忍不住入手了一个,就是orange pi 感兴趣的可以百度搜索下,深圳一个公司出的,不过资料比树莓派少了很多,论坛中人也没多少, ...

  4. POJ 1014 Dividing

    Dividing Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 66032 Accepted: 17182 Descriptio ...

  5. CF 371B Fox Dividing Cheese[数论]

    B. Fox Dividing Cheese time limit per test 1 second memory limit per test 256 megabytes input standa ...

  6. AC日记——Dividing poj 1014

    Dividing Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 69575   Accepted: 18138 Descri ...

  7. POJ 1014 Dividing(多重背包)

    Dividing   Description Marsha and Bill own a collection of marbles. They want to split the collectio ...

  8. Dividing a Chocolate(zoj 2705)

    Dividing a Chocolate zoj 2705 递推,找规律的题目: 具体思路见:http://blog.csdn.net/u010770930/article/details/97693 ...

  9. 动态规划--模板--hdu 1059 Dividing

    Dividing Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total S ...

随机推荐

  1. VS 2017 统计项目代码总行数

    编辑 → 查找和替换 → 在文件中的查找,打开查找窗口 填入正则表达式  ^b*[^:b#/]+.*$ 查找范围选“整个解决方案”,勾选上“使用正则表达式” 如果要限制文件类型,就填上要查找的文件类型 ...

  2. MySQL创建临时表

    drop TEMPORARY table if EXISTS temp_table; create TEMPORARY table temp_table( id int not null, usern ...

  3. HTTP 下载文件中文文件名在 Firefox 下乱码问题

    转自:http://www.imhdr.com/991/ HTTP 下载文件,中文文件名在 Firefox 下乱码问题 最近帮助一同事解决 HTTP 下载文件时,中文文件名在 Firefox 下乱码的 ...

  4. HDU1850 - Being a Good Boy in Spring Festival 【尼姆博弈】

    一年在外 父母时刻牵挂  春节回家 你能做几天好孩子吗  寒假里尝试做做下面的事情吧  陪妈妈逛一次菜场  悄悄给爸爸买个小礼物  主动地 强烈地 要求洗一次碗  某一天早起 给爸妈用心地做回早餐  ...

  5. 《奋斗吧!菜鸟》 第八次作业:Alpha冲刺 Scrum meeting 4

    项目 内容 这个作业属于哪个课程 任课教师链接 作业要求 https://www.cnblogs.com/nwnu-daizh/p/11012922.html 团队名称 奋斗吧!菜鸟 作业学习目标 A ...

  6. Co-prime

    Co-prime Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Problem ...

  7. MySQL Migration Toolkit v2.1特别版

    MySQL数据库转换工具MySQL Migration Toolkit v2.1特别版 支持mssql\oracle\access\excel与mysql互换 可以将任何数据源转换成mysql的数据, ...

  8. 0918如何利用jmeter为数据库插入测试数据

    第一 制定测试计划,关于JMETER会通过驱动取操作数据库,因而请在底部路径填写正确. 下载该资源http://download.csdn.net/download/fnngj/3451945 第二步 ...

  9. E - Just a Hook

    E - Just a Hook HDU 1698 思路:区间修改即可. #include<cstdio> #include<cstring> #include<iostr ...

  10. spring-logback

    <?xml version="1.0" encoding="UTF-8"?><!-- 说明: 1.日志级别及文件 日志记录采用分级记录,级别与 ...