Advertisement
krutzz

Untitled

Sep 5th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.46 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Taks5
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             var n = int.Parse(Console.ReadLine());
  14.             var arr = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
  15.  
  16.             int max = int.MinValue;
  17.  
  18.             var d = new int[n];
  19.             var memo = new int[n];
  20.             for (int i = 0; i < n; i++)
  21.             {
  22.                 memo[i] = -1;
  23.             }
  24.  
  25.             for (int i = n - 2; i >= 0; i--)
  26.             {
  27.                 int j = i + 1;
  28.                 int tmp = arr[i];
  29.                 while (j < n)
  30.                 {
  31.                     if (tmp < arr[j])
  32.                     {
  33.                         if (memo[j] >= 0)
  34.                         {
  35.                             d[i] = memo[j] + 1;
  36.                             break;
  37.                         }
  38.                         else
  39.                         {
  40.                             d[i]++;
  41.                             tmp = arr[j];
  42.                         }
  43.                     }
  44.                     j++;
  45.                 }
  46.  
  47.                 memo[i] = d[i];
  48.  
  49.                 if (max < d[i])
  50.                 {
  51.                     max = d[i];
  52.                 }
  53.             }
  54.             Console.WriteLine(max);
  55.             Console.WriteLine(string.Join(" ", d));
  56.         }
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement