public static void Main()
int [] A = new int[] {1,1,3,3,4,4,4,5,5,6,6,6,6,6,6};
var result = Program.Solution(A, K);
Console.WriteLine(result);
public static int Solution(int[] A, int K)
for(int i = 0; i < n - K - 1; i++)
int result = best+K > Math.Min(K+1, n) ? (best+K) : Math.Min(K+1, n);