1851 - Bridge Coverage Systems

Discussion around the problems of the COJ.
Forum rules
Remember that posting AC code is not allowed here. If you are going to ask a question or to post a solution, describe your algorithm instead. Posting AC code will be penalized.
Post Reply
User avatar
ymondelo20
Posts: 1968
Joined: 8 years ago
Location: Universidad de las Ciencias Informáticas
Gender: None specified
Contact:

1851 - Bridge Coverage Systems

Post by ymondelo20 » 7 years ago



"Every problem has a simple, fast and wrong solution" OJ's Main Law. ;)

axlluis
Posts: 17
Joined: 7 years ago
Gender: None specified

Re: 1851 - Bridge Coverage Systems

Post by axlluis » 7 years ago

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);
            }
        }
    }
}

User avatar
Phantom
Posts: 58
Joined: 8 years ago
Location: Cuba
Gender: None specified

Re: 1851 - Bridge Coverage Systems

Post by Phantom » 7 years ago

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. ;)

User avatar
JJRZ
Posts: 13
Joined: 8 years ago
Location: UH
Gender: None specified

Re: 1851 - Bridge Coverage Systems

Post by JJRZ » 7 years ago

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

Post Reply

Return to “Problem set”