Advertisement
unrealbg

Untitled

Jan 30th, 2023
729
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.08 KB | None | 0 0
  1. using System;
  2.  
  3. namespace HeroGame
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int n = int.Parse(Console.ReadLine());
  10.             string[] input = Console.ReadLine().Split(' ');
  11.             int[] safehouses = new int[input.Length];
  12.             for (int i = 0; i < input.Length; i++)
  13.             {
  14.                 safehouses[i] = int.Parse(input[i]);
  15.             }
  16.  
  17.             int greatestDistance = 0;
  18.             for (int i = 0; i < n; i++)
  19.             {
  20.                 int minDistance = int.MaxValue;
  21.                 for (int j = 0; j < safehouses.Length; j++)
  22.                 {
  23.                     int distance = Math.Abs(i - safehouses[j]);
  24.                     if (distance < minDistance)
  25.                     {
  26.                         minDistance = distance;
  27.                     }
  28.                 }
  29.  
  30.                 if (minDistance > greatestDistance)
  31.                 {
  32.                     greatestDistance = minDistance;
  33.                 }
  34.             }
  35.  
  36.             Console.WriteLine(greatestDistance);
  37.         }
  38.     }
  39. }
  40.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement