1
I’m solving that URI Online Judge challenge.
But my code has had the answer "Time limit exceeded", and I don’t understand exactly why.
Follows code below:
using System;
using System.Linq;
namespace URI_1259
{
class Program
{
static void Main(string[] args)
{
int numero = int.Parse(Console.ReadLine());
int i;
int[] arr = new int[numero];
int[] numeroParCrescente = new int[numero];
int[] numeroImparDecrescente = new int[numero];
for (i = 0; i < arr.Length; i++)
{
arr[i] = int.Parse(Console.ReadLine());
numeroParCrescente = arr.Where(x => x % 2 == 0).OrderBy(x => x).ToArray();
numeroImparDecrescente = arr.Where(x => x % 2 != 0).OrderByDescending(x => x).ToArray();
}
foreach(var item in numeroParCrescente)
{
Console.WriteLine(item);
}
foreach(var item in numeroImparDecrescente)
{
Console.WriteLine(item);
}
}
}
}
What is the reason, or some way to optimize?