Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- class Program
- {
- static void Main()
- {
- int n = int.Parse(Console.ReadLine());
- int[] locations = new int[n];
- for (int i = 0; i < locations.Length; i++)
- {
- locations[i] = 0;
- }
- int[] safeHouse = Console.ReadLine().Split().Select(int.Parse).ToArray();
- for (int i = 0; i < locations.Length; i++)
- {
- if (safeHouse.Contains(i))
- {
- locations[i] = 1;
- }
- }
- int maxDistance = 0;
- int currentLenght = 0;
- for (int i = 0; i < locations.Length; i++)
- {
- if (locations[i] == 0)
- {
- currentLenght++;
- }
- else
- {
- if (maxDistance < currentLenght)
- {
- maxDistance = currentLenght;
- }
- currentLenght = 0;
- }
- }
- if (safeHouse.Length > 1)
- {
- maxDistance = (int)Math.Ceiling(maxDistance / 2.0);
- }
- else if (locations[0] == 1 && locations[locations.Length - 1] == 1)
- {
- maxDistance = locations.Length - 3;
- }
- Console.WriteLine(maxDistance);
- }
- }
Add Comment
Please, Sign In to add comment