Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace _05._Fashion_Boutique
- {
- class Program
- {
- static void Main(string[] args)
- {
- var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
- int rackCapacity = int.Parse(Console.ReadLine());
- int rackCounter = 1;
- Stack<int> clothesValues = new Stack<int>(input);
- int currentClothesValue = 0;
- for (int i = 0; i < clothesValues.Count; i++)
- {
- int currentClothValue = clothesValues.Pop();
- if (rackCapacity - (currentClothesValue + currentClothValue) > 0)
- {
- currentClothesValue += currentClothValue;
- i--;
- }
- else if (rackCapacity - (currentClothesValue + currentClothValue) == 0)
- {
- if (clothesValues.Count != 0)
- {
- rackCounter++;
- currentClothesValue = 0;
- i--;
- }
- }
- else if (rackCapacity - (currentClothesValue + currentClothValue) < 0)
- {
- clothesValues.Push(currentClothValue);
- rackCounter++;
- currentClothesValue = 0;
- i--;
- }
- }
- Console.WriteLine(rackCounter);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement