-
Notifications
You must be signed in to change notification settings - Fork 2
/
c.java
38 lines (37 loc) · 1.14 KB
/
c.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import java.io.*;
import java.util.*;
public class a{
static BufferedReader br;
static PrintWriter pw;
public static void main(String args[]) throws IOException{
br = new BufferedReader(new InputStreamReader(System.in));
pw = new PrintWriter(System.out);
int N = Integer.parseInt(br.readLine());
int p[] = new int[N];
StringTokenizer st = new StringTokenizer(br.readLine());
for(int i = 0; i < N; i++){
p[i] = Integer.parseInt(st.nextToken());
}
int mat[][] = new int[N][N];
for(int i = 0; i < N; i++) Arrays.fill(mat[i], -1);
for(int i = 0; i < N; i++){
int x = i, y = i;
int nm = p[i];
for(int j = 0; j < nm; j++){
mat[x][y] = nm;
if(y > 0 && mat[x][y-1] == -1){
y--;
}else{
x++;
}
}
}
for(int i = 0; i < N; i++){
for(int j = 0; j <= i; j++){
pw.print(mat[i][j] + " ");
}
pw.println();
}
br.close(); pw.close();
}
}