Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package second;
- import java.util.Scanner;
- import java.util.Stack;
- public class CokiSkoki {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- Stack<Integer> buildings = new Stack<>();
- int n = sc.nextInt();
- for (int i = 0; i < n; i++) {
- buildings.push(sc.nextInt());
- }
- Stack<Integer> jumpSize = new Stack<>();
- Stack<Integer> result = new Stack<>();
- int max = 0;
- while (!buildings.isEmpty()) {
- if (jumpSize.isEmpty()) {
- jumpSize.push(buildings.pop());
- result.push(0);
- } else if (buildings.peek() < jumpSize.peek()) {
- jumpSize.push(buildings.pop());
- result.push(jumpSize.size() - 1);
- } else {
- jumpSize.pop();
- }
- if (max < result.peek()) {
- max = result.peek();
- }
- }
- System.out.println(max);
- while (!result.isEmpty()) {
- System.out.print(result.pop() + " ");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement