zadanie Arraysub zwraca mi time limit exceeded a jak poprwawić pogram by nie zwracał błedu
using System;
using System.Linq;
namespace ConsoleApp17
{
internal class Program
{
private static void Main(string[] args)
{
int n = Convert.ToInt32((Console.ReadLine()));
int k;
int val = 0;
int[] arr = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
k = Convert.ToInt32((Console.ReadLine()));
for (int i = 0; i < n - k + 1; i++)
{
val = arr[i];
for (int j = i; j < i + k; j++)
{
if (val < arr[j])
{
val = arr[j];
}
}
Console.Write(val + " ");
}
}
}
}