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. Gartner2017年数据科学领域最酷供应商出炉,实至名归

    文 | 帆软数据应用研究院 水手哥 更多大数据资讯和企业案例可关注 :知乎专栏<帆软数据应用研究院> 近日,Gartner公布了2017年度数据科学和机器学习领域的最酷供应商,清一色的美国 ...

  2. PJAX全局无刷新的设置方法~

    先添加必要文件: <script src="http://cdn.bootcss.com/jquery/1.11.1/jquery.min.js"></scrip ...

  3. POJ_2594_最小路径覆盖

    Treasure Exploration Time Limit: 6000MS   Memory Limit: 65536K Total Submissions: 8085   Accepted: 3 ...

  4. APICloud 获取缓存以及清除缓存(常用第三方方法)

    一.app中经常会有缓存的清除这个操作,具体如下 1.获取缓存大小 apiready = function() { api.getCacheSize(function(ret, err) { //si ...

  5. console.log、toString方法与js判断变量类型

    Java调用system.print.out()是会调用toString方法打印js里的console.log也是控制台打印,很多时候,我们以为也是调用toString方法,其实并不是.我们在chro ...

  6. 前端面试题总结 -vue

    1.active-class是哪个组件的属性? vue-router模块的router-link组件. 2.嵌套路由怎么定义? 在 VueRouter 的参数中使用 children 配置,这样就可以 ...

  7. localStorage、sessionStorage、cookie

    vue下的全局变量和vuex里的state都是临时变量,页面刷新就都没了.

  8. Day 20 python基础总复习

    一.计算机基础 1.1 计算机基础之编程 编程语言是人与计算机之间交流的介质 编程就是写一堆文件 编程为了奴隶计算机,解放劳动力 1.2 计算机组成原理 CPU 控制器:控制硬件 运算器:逻辑运算和算 ...

  9. C++引用、类型转换、类和对象(day03)

    十 C++的引用(Reference) 引用型函数参数 )将引用用于函数的参数,可以修改实参变量的值,同时也能减小函数调用的开销. )引用参数有可能意外修饰实参的值,如果不希望修改实参变量本身,可以将 ...

  10. python爬虫05 | 年轻人,不会正则表达式你睡得着觉?有点出息没有?

    现在 你已经会使用 python 模拟浏览器 进行一些 Http 的请求了 那么请求完之后 服务器返回给我们一堆源代码 我们可不是啥都要的啊 我们是有原则的 我们想要的东西 怎么能一股脑的啥都往自己兜 ...