Advertisement
Prohause

Fashion boutique

Jun 8th, 2020
772
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace FashionBoutique
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. var clothValues = Console.ReadLine().Split(' ').Select(int.Parse).Reverse().ToList();
  12. var capacity = int.Parse(Console.ReadLine());
  13.  
  14. var racks = 0;
  15. var sum = 0;
  16.  
  17. var box = new Stack<int>(clothValues);
  18.  
  19. while(box.Count> 0)
  20. {
  21. var currentSize = sum + box.Peek();
  22.  
  23. if (currentSize < capacity)
  24. {
  25. sum += box.Pop();
  26. }
  27. else if(currentSize == capacity)
  28. {
  29. racks++;
  30. box.Pop();
  31. sum = 0;
  32. }
  33. else
  34. {
  35. racks++;
  36. sum = box.Pop();
  37. }
  38. }
  39.  
  40. if (sum > 0)
  41. {
  42. racks++;
  43. }
  44.  
  45. Console.WriteLine(racks);
  46. }
  47. }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement