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;
- using System.Threading.Tasks;
- namespace Taks5
- {
- class Program
- {
- static void Main(string[] args)
- {
- var n = int.Parse(Console.ReadLine());
- var arr = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
- int max = int.MinValue;
- var d = new int[n];
- var memo = new int[n];
- for (int i = 0; i < n; i++)
- {
- memo[i] = -1;
- }
- for (int i = n - 2; i >= 0; i--)
- {
- int j = i + 1;
- int tmp = arr[i];
- while (j < n)
- {
- if (tmp < arr[j])
- {
- if (memo[j] >= 0)
- {
- d[i] = memo[j] + 1;
- break;
- }
- else
- {
- d[i]++;
- tmp = arr[j];
- }
- }
- j++;
- }
- memo[i] = d[i];
- if (max < d[i])
- {
- max = d[i];
- }
- }
- Console.WriteLine(max);
- Console.WriteLine(string.Join(" ", d));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement