Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedReader;
- import java.io.ByteArrayInputStream;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.util.Arrays;
- import java.util.Stack;
- public class Cokiskoki {
- public static void main(String[] args) throws IOException {
- testInput();
- BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
- in.readLine();
- int max = 0;
- int[] arr = Arrays.stream(in.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
- int out[] = new int[arr.length];
- for (int i = arr.length - 2; i >= 0; i--) {
- for (int j = i + 1; j < arr.length; j++) {
- if (arr[i] < arr[j]) {
- out[i] = out[j] + 1;
- max = Math.max(max, out[i]);
- break;
- }
- }
- }
- StringBuilder result = new StringBuilder("");
- for (int i = 0; i < out.length; i++) {
- result.append(out[i]);
- result.append(" ");
- }
- System.out.println(max);
- System.out.println(result.toString().trim());
- // System.out.println(result.reverse().toString().trim());
- }
- public static void testInput() {
- String test = "5\n" +
- "1 1 1 1 1";
- System.setIn(new ByteArrayInputStream(test.getBytes()));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement