Guest User

Untitled

a guest
Aug 10th, 2023
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. class Program
  7. {
  8. static void Main()
  9. {
  10. int n = int.Parse(Console.ReadLine());
  11. int[] locations = new int[n];
  12.  
  13. for (int i = 0; i < locations.Length; i++)
  14. {
  15. locations[i] = 0;
  16. }
  17.  
  18. int[] safeHouse = Console.ReadLine().Split().Select(int.Parse).ToArray();
  19.  
  20. for (int i = 0; i < locations.Length; i++)
  21. {
  22. if (safeHouse.Contains(i))
  23. {
  24. locations[i] = 1;
  25. }
  26. }
  27.  
  28. int maxDistance = 0;
  29. int currentLenght = 0;
  30.  
  31. for (int i = 0; i < locations.Length; i++)
  32. {
  33. if (locations[i] == 0)
  34. {
  35. currentLenght++;
  36. }
  37. else
  38. {
  39. if (maxDistance < currentLenght)
  40. {
  41. maxDistance = currentLenght;
  42. }
  43. currentLenght = 0;
  44. }
  45.  
  46. }
  47.  
  48. if (safeHouse.Length > 1)
  49. {
  50. maxDistance = (int)Math.Ceiling(maxDistance / 2.0);
  51. }
  52. else if (locations[0] == 1 && locations[locations.Length - 1] == 1)
  53. {
  54. maxDistance = locations.Length - 3;
  55. }
  56. Console.WriteLine(maxDistance);
  57. }
  58. }
Add Comment
Please, Sign In to add comment