CSharp · Console
using System;
using System.Linq;
public class Program
{
public static double GetMaxDistance(double fullDistance, double[] pitstops)
{
// сортируем позиции питстопов
pitstops = pitstops.OrderBy(x => x).ToArray();
int count = pitstops.Length;
// расстояние между 1м и последним питстопом d(0, count-1) равно
// Общее расстояние - позиция последнего питстопа - позиция 1го питстопа
double res = fullDistance - pitstops[count - 1] + pitstops[0];
for (int i = 0; i < count - 1; i++)
{
res = Math.Max(res, pitstops[i + 1] - pitstops[i]);
}
return res / 2.0;
}
public static void Main()
{
Console.WriteLine("UniLecs");
double[] arr = new double[] { 4.5, 0.5, 2, 1 };
Console.WriteLine(string.Format("Answer = {0}", GetMaxDistance(5, arr))); // 1.25
}
}