I can think of this solution Put first elements in a max heap ..O(10)
Now take 11 th element ..compare it with root of this max heap ..If less than root ignore ..else remove root and call max-heapify and put this element in right place Similarly do this for rest Complexity will be n+nlogk where k is 10 Please put ur comments and correct if wrong !! Regards Ankur On Mon, Aug 8, 2011 at 4:36 PM, shady <[email protected]> wrote: > @DK can you please explain your solution, i couldn't understand... > > @all any alternate solution ? > > > On Sun, Aug 7, 2011 at 11:02 PM, DK <[email protected]> wrote: > >> This is a simple problem: >> >> 1. Understand that if you are selecting 2 petrol pumps, say P and Q with >> say another petrol pump R between them, then it is optimal to include R into >> the set of selected petrol pumps as the max-distance for the chosen pumps >> remains PQ but number of included petrol pumps is reduced. >> >> Diagram: P --- R --- Q >> >> Therefore, all the selected pumps in the final solution are going to be >> contiguous. >> >> The simplest solution thus is to sort the points along the line AB. O(n >> log n) >> Then the answer is min{ai+10 - ai} for i = 0 to N-11 - O(n) >> >> Therefore net complexity is O(n log n). >> If the petrol pumps are given in sorted order from distance from A, then >> the complexity is simply O(n). >> >> -- >> DK >> >> http://gplus.to/divyekapoor >> http://www.divye.in >> http://twitter.com/divyekapoor >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Algorithm Geeks" group. >> To view this discussion on the web visit >> https://groups.google.com/d/msg/algogeeks/-/m1jZuQUY85AJ. >> >> To post to this group, send email to [email protected]. >> To unsubscribe from this group, send email to >> [email protected]. >> For more options, visit this group at >> http://groups.google.com/group/algogeeks?hl=en. >> > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
