Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace P10.PoisonousPlants
- {
- internal class PoisonousPlants
- {
- static void Main(string[] args)
- {
- int plantsCount = int.Parse(Console.ReadLine());
- int[] pesticidesOfEachPlant = Console.ReadLine()
- .Split(' ', StringSplitOptions.RemoveEmptyEntries)
- .Select(int.Parse)
- .ToArray();
- Stack<int> stack = new Stack<int>(pesticidesOfEachPlant);
- Stack<int> tempStack = new Stack<int>();
- int savedNumber = stack.Pop();
- bool isDayWithoutDying = true;
- int dayWithoutDyingCount = 0;
- while (true)
- {
- if (savedNumber <= stack.Peek())
- {
- tempStack.Push(savedNumber);
- }
- else
- {
- isDayWithoutDying = false;
- }
- savedNumber = stack.Pop();
- if (stack.Count == 0)
- {
- if (isDayWithoutDying || tempStack.Count == 0)
- {
- Console.WriteLine(dayWithoutDyingCount);
- break;
- }
- tempStack.Push(savedNumber);
- dayWithoutDyingCount++;
- isDayWithoutDying = true;
- stack = new Stack<int>(tempStack);
- tempStack.Clear();
- savedNumber = stack.Pop();
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement