Advertisement
PetarNeshkov5360

02. The Lift

Aug 26th, 2020
447
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.13 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Program
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. int WaitingPeople = int.Parse(Console.ReadLine());
  12. int[] currentState = Console.ReadLine().Split().Select(int.Parse).ToArray();
  13. int nondifference = 0;
  14. for (int i = 0; i < currentState.Length; i++)
  15. {
  16.  
  17.  
  18. if (currentState[i] >= 4)
  19. {
  20. currentState[i] = 4;
  21. WaitingPeople -= currentState[i];
  22.  
  23. }
  24. else if (currentState[i] == 0||currentState[i]<0)
  25. {
  26. int PreviousLeft;
  27. PreviousLeft = WaitingPeople;
  28. if (PreviousLeft - 4 < 0)
  29. {
  30. currentState[i] = PreviousLeft;
  31. }
  32. else currentState[i] = 4;
  33. WaitingPeople -= currentState[i];
  34.  
  35. }
  36. else if (currentState[i] < 4)
  37. {
  38. WaitingPeople -= currentState[i];
  39. currentState[i] = 4;
  40. }
  41. }
  42. for (int i = 0; i < currentState.Length; i++)
  43. {
  44. if (currentState[i]!=4)
  45. {
  46. nondifference++;
  47.  
  48. }
  49. }
  50.  
  51. if (WaitingPeople <= 0&&nondifference!=0)
  52. {
  53. Console.WriteLine("The lift has empty spots!");
  54. Console.WriteLine(String.Join(" ", currentState));
  55.  
  56. }
  57. else if (WaitingPeople>0&&nondifference==0)
  58. {
  59. Console.WriteLine($"There isn't enough space! {WaitingPeople} people in a queue!");
  60. Console.WriteLine(String.Join(" ", currentState));
  61. }
  62. else if (WaitingPeople <= 0 && nondifference == 0)
  63. {
  64. Console.WriteLine(String.Join(" ", currentState));
  65. }
  66. }
  67. }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement