algorithm - Find minimum time required to collect C gifts from A machines given access to B bags? -


I have an interview next week and I am practicing problems for the same. I came to this question, can you please solve it?

A gift vending machine and you have to collect b sachet / strong> gifts. Each gift vending machine has unlimited gifts.

Each machine started leaving gifts at the time C and left the gift every Ii seconds. You can arrange pouch in any way, but once they are set below a machine, you can not take it on any other machine. You need to collect the gifts in the shortest possible time.

Input

The first line contains integers A, B, C.

The integer in the second row, C (different from one space), I go from 1 to A.

In the third line, integers Ii (different from one space), I go from 1 to A.

Output

An integer that calculates the minimum time

I think the method was very incompatible. I thought that all of us can equate the subsets of all to the equivalent of their cardinal number B. And then select the one that gives the minimum time .

This approach seems to be brute force, so I'm looking for another alternative approach.

Can any of you help me with it?

first write a function

  int max_num_gifts (A, B , T, S [], L [])   

which you can calculate the maximum number of gifts t can be done in time: S [] and l [] number of gifts machine A [ I] drops is (ts [i]) / l [i] + 1 . Then the top B machines that leave the most gifts. See on how to select O (n) in time.

Then you can only loop through time t = 1,2, ... until max_num_gifts & gt; = C Or better still, you can use a binary search to search such a t : Start with t = 1 Then t = 2 , T = 4 , t = 8 etc. Unless you receive a large number, then the required t Binary search for .

Complexity of overall time should be O (A * lg (T_min)) .

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -