daily pastebin goal
60%
SHARE
TWEET

Untitled

a guest Jan 24th, 2019 73 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //https://judge.telerikacademy.com/problem/05cokiskoki
  2.  
  3.  
  4. import java.io.BufferedReader;
  5. import java.io.ByteArrayInputStream;
  6. import java.io.IOException;
  7. import java.io.InputStreamReader;
  8. import java.util.Arrays;
  9. import java.util.Stack;
  10.  
  11. public class Cokiskoki {
  12.  
  13.  
  14.     public static void main(String[] args) throws IOException {
  15.  
  16.  
  17.         testInput();
  18.         BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
  19.         in.readLine();
  20.         int max = 0;
  21.  
  22.  
  23.         int[] arr = Arrays.stream(in.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
  24.         int out[] = new int[arr.length];
  25.  
  26.  
  27.         for (int i = arr.length - 2; i >= 0; i--) {
  28.             for (int j = i + 1; j < arr.length; j++) {
  29.                 if (arr[i] < arr[j]) {
  30.                     out[i] = out[j] + 1;
  31.                     max = Math.max(max, out[i]);
  32.                     break;
  33.                 }
  34.             }
  35.         }
  36.  
  37.  
  38.         StringBuilder result = new StringBuilder("");
  39.         for (int i = 0; i < out.length; i++) {
  40.             result.append(out[i]);
  41.             result.append(" ");
  42.         }
  43.  
  44.         System.out.println(max);
  45.         System.out.println(result.toString().trim());
  46.  
  47. //        System.out.println(result.reverse().toString().trim());
  48.  
  49.  
  50.  
  51.  
  52.  
  53.     }
  54.  
  55.     public static void testInput() {
  56.         String test = "5\n" +
  57.                 "1 1 1 1 1";
  58.         System.setIn(new ByteArrayInputStream(test.getBytes()));
  59.     }
  60.  
  61. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top