Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- class Program
- {
- static void Main()
- {
- int N = int.Parse(Console.ReadLine());
- string init = Console.ReadLine();
- int[] elements = init.Split().Select(int.Parse).ToArray();
- int[] jumps = new int[N];
- Stack<int> indexStack = new Stack<int>();
- int maxJumps = 0;
- for (int i = 0; i < elements.Length; i++)
- {
- int initialIndex = i;
- if (jumps[i] == 0)
- {
- for (int j = i; j < elements.Length; j++)
- {
- if ((elements[j] > elements[initialIndex]))
- {
- indexStack.Push(initialIndex);
- initialIndex = j;
- }
- }
- int count = 1;
- while (indexStack.Count > 0)
- {
- int index = indexStack.Pop();
- jumps[index] = count;
- count++;
- maxJumps = Math.Max(maxJumps, jumps[index]);
- }
- }
- }
- Console.WriteLine(maxJumps);
- Console.WriteLine(string.Join(" ", jumps));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement