Page 1 of 1

1851 - Bridge Coverage Systems

Posted: Wed May 30, 2012 11:45 pm
by ymondelo20

Re: 1851 - Bridge Coverage Systems

Posted: Thu Jun 28, 2012 11:22 am
by axlluis
whye i received time limited exeded if mi code is simple like this:

Code: Select all

using System;

namespace _1851_Bridge_Coverage_Systems
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] towers = new int[n];
            int may = int.MinValue;
            for (int i = 0; i < n; i++)
            {
                int h = int.Parse(Console.ReadLine());
                towers[i] = h;
                if (h > may)
                {
                    may = h;
                }
            }
            foreach (int x in towers)
            {
                Console.WriteLine(may - x);
            }
        }
    }
}

Re: 1851 - Bridge Coverage Systems

Posted: Fri Jul 13, 2012 12:09 pm
by Phantom
Your algorithm is very fine and very fast, I can't understand why you received an TLE. Try it in Ruby with the same algorithm. I did the same like you in Ruby, and I received an Accepted. ;)

Re: 1851 - Bridge Coverage Systems

Posted: Fri Jul 13, 2012 1:52 pm
by JJRZ
Maybe if you do "may = towers.Max()" when you read it all, you can eliminate the "if(h > may){ }" sentence. I do that and I received an Accepted