using System; using System.Collections.Generic; using System.Linq; namespace _05_Fashion_Boutique { class Program { static void Main(string[] args) { var priceOfClothes = Console.ReadLine().Split().Select(int.Parse).ToArray(); int capacityOfARack = int.Parse(Console.ReadLine()); Stack prices = new Stack(priceOfClothes); int sumOfClothes = 0; int numOfRacks = 1; //5 4 8 6 3 8 7 7 9 --- orders //16 -- capacity for (int i = 0; i < priceOfClothes.Length; i++) { sumOfClothes += priceOfClothes[i]; if (sumOfClothes == capacityOfARack) { numOfRacks++; sumOfClothes = 0; if (prices.Any()) { continue; } } else if (sumOfClothes > capacityOfARack) { numOfRacks++; sumOfClothes = 0; i--; if (prices.Any()) { continue; } } prices.Pop(); } Console.WriteLine(numOfRacks); } } }