Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace P05FashionBoutique
- {
- using System;
- using System.Collections.Generic;
- using System.Linq;
- public class StartUp
- {
- public static void Main(string[] args)
- {
- int[] clothes = Console.ReadLine()
- .Split(" ", StringSplitOptions.RemoveEmptyEntries)
- .Select(int.Parse)
- .ToArray();
- Stack<int> stack = new Stack<int>(clothes);
- int capacity = int.Parse(Console.ReadLine());
- int sum = 0;
- int numberOfRacks = 1;
- if (stack.Sum() == 0)
- {
- Console.WriteLine("0");
- return;
- }
- while (sum < capacity && stack.Count > 0)
- {
- sum += stack.Peek();
- if (sum == capacity && stack.Count > 0)
- {
- numberOfRacks++;
- sum = 0;
- }
- else if (sum == capacity && stack.Count == 0)
- {
- break;
- }
- else if (sum > capacity)
- {
- numberOfRacks++;
- sum = stack.Pop();
- continue;
- }
- stack.Pop();
- }
- Console.WriteLine(numberOfRacks);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement