Guest User

Untitled

a guest
Jan 24th, 2018
331
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.73 KB | None | 0 0
  1. namespace _11.PoisonousPlants
  2. {
  3.     using System;
  4.     using System.Linq;
  5.  
  6.     class Program
  7.     {
  8.         static void Main()
  9.         {
  10.             int n = int.Parse(Console.ReadLine());
  11.             int[] plants = Console.ReadLine().Split().Select(int.Parse).ToArray();
  12.             int[] days = new int[n];
  13.             int[] minElement = new int[n];
  14.  
  15.             int min = int.MaxValue;
  16.             for (int i = 0; i < n; i++)
  17.             {
  18.                 if (plants[i] < min)
  19.                 {
  20.                     min = plants[i];
  21.                 }
  22.                 minElement[i] = min;
  23.             }
  24.  
  25.             int max = 0;
  26.             int maxIndex = 0;
  27.  
  28.             for (int i = 1; i < n; i++)
  29.             {
  30.                 if (plants[i] > plants[i - 1])
  31.                 {
  32.                     days[i] = 1;
  33.                     if (days[i] >= max)
  34.                     {
  35.                         maxIndex = i;
  36.                         max = days[i];
  37.                     }
  38.                     continue;
  39.                 }
  40.  
  41.                 if (plants[i] > minElement[i])
  42.                 {
  43.                     if (plants[i] > plants[maxIndex])
  44.                     {
  45.                         days[i] = days[i-1]+1;
  46.                     }
  47.                     else
  48.                     {
  49.                         days[i] = days[maxIndex] + 1;
  50.                     }
  51.                 }
  52.                 if(plants[i] == minElement[i])
  53.                 {
  54.                    max=0;
  55.                 }  
  56.  
  57.                 if (days[i] >= max)
  58.                 {
  59.                     maxIndex = i;
  60.                     max = days[i];
  61.                 }
  62.             }
  63.  
  64.             Console.WriteLine(days.Max());
  65.         }
  66.     }
  67. }
Add Comment
Please, Sign In to add comment