Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Linq;
- namespace Advanced
- {
- class Program
- {
- static void Main(string[] args)
- {
- var stackOfClothes = new Stack<int>(Console.ReadLine().Split().Select(int.Parse));
- int rackCapacity = int.Parse(Console.ReadLine());
- int sumValue = 0;
- int countRacks = 1;
- while (stackOfClothes.Any())
- {
- if (sumValue + stackOfClothes.Peek() <= rackCapacity)
- {
- sumValue += stackOfClothes.Pop();
- }
- else
- {
- sumValue = 0;
- countRacks++;
- }
- }
- Console.WriteLine(countRacks);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment