'How Can I reduce execution time in SPOJ problem?
I am trying to solve the problem on SPOJ.COM and although the answer is good it shows that the time limit has been exceeded. How can I correct it so that the task will be completed? This is problem to solve on SPOJ: https://www.spoj.com/problems/ARRAYSUB/
using System;
using System.Linq;
public class Test
{
public static void Main()
{
int n = Convert.ToInt32(Console.ReadLine());
int k;
int m = 0;
int[] a = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
k = Convert.ToInt32((Console.ReadLine()));
for (int i = 0; i <=n - k ; i++)
{
m = a[i];
for (int j = 1; j < k; j++)
{
if (a[i + j] > m)
{
m = a[i + j];
}
}
Console.Write(m);
Console.Write(" ");
}
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
