// Codeforces Round #150 (Div. 2): A - Dividing Orange
import java.io.*;
import java.math.*;
import java.util.*;
public class MainCodeforces1 {
private static MyScanner in;
private static PrintStream out;
public static void main(String[] args) throws IOException {
// helpers for input/output
boolean LOCAL_TEST = false;
// LOCAL_TEST = true;// comment it before submitting
out = System.out;
if (LOCAL_TEST) {
in = new MyScanner("E:\\zin2.txt");
}
else {
boolean usingFileForIO = false;
if (usingFileForIO) {
// using input.txt and output.txt as I/O
in = new MyScanner("input.txt");
out = new PrintStream("output.txt");
}
else {
in = new MyScanner();
out = System.out;
}
}
solve();
}
private static void solve() throws IOException
{
int N = in.nextInt();
int K = in.nextInt();
// int[] nums = new int[K];
boolean[] used = new boolean[N * K + 1];
for (int i = 1; i <= N * K; i++) {
used[i] = false;
}
Map<Integer, List<Integer>> map = new HashMap<Integer, List<Integer>>();
for (int i = 1; i <= K; i++) {
int x = in.nextInt();
List<Integer> l = new ArrayList<Integer>();
l.add(x);
used[x] = true;
map.put(i, l);
}
int iused = 1;
for (int i = 1; i <= K; i++) {
List<Integer> ls = map.get(i);
while (ls.size() < N) {
while (used[iused]) {
iused++;
}
used[iused] = true;
ls.add(iused);
}
map.put(i, ls);
}
for (int i = 1; i <= K; i++) {
List<Integer> ls = map.get(i);
for (int j = 0; j < ls.size(); j++) {
if (j > 0)
out.print(" ");
out.print(ls.get(j));
}
out.println();
}
}
static class MyScanner {
StreamTokenizer in;
public MyScanner() throws IOException
{
Reader r = new BufferedReader(new InputStreamReader(System.in));
in = new StreamTokenizer(r);
}
public MyScanner(String inputFile) throws IOException {
Reader r;
r = new BufferedReader(new FileReader(inputFile));
in = new StreamTokenizer(r);
}
public int nextInt() throws IOException {
in.nextToken();
return (int) in.nval;
}
public long nextLong() throws IOException {
in.nextToken();
return (long) in.nval;
}
public double nextDouble() throws IOException {
in.nextToken();
return in.nval;
}
public String nextString() throws IOException {
in.nextToken();
return in.sval;
}
}
}
No comments:
Post a Comment