Riding jet skis is popular again, so let’s have a race! Unfortunately not all jet skis are equally fast, so to make the race more fair, the jet skis don’t all start at the same position (i.e., there’s no start line that all jet skis start from). You are the commentator and so you need to comment on which jet ski is in the lead. Formally, we are given n jet skis, traveling parallel to each other to avoid collisions (from left to right from your perspective). Each jet ski i travels at a constant speed vi. At time t = 0 the jet skis are at positions p1, ..., pn. We say that a jet ski is in the lead if its position is to the right of all other jet skis. Design an algorithm that computes the set of all jet skis that are in the lead at some point in time. For example, if we had 3 jet skis with speed 1, 2, and 3 and starting positions 10, 0, −1, your algorithm needs to report jet ski 1 (which is in the lead at time t = 0) and jet ski 3 (which is in the lead from t = 5.5). Your algorithm should not report jet ski 2, as this jet ski is never in the lead. As usual, also prove its correctness and analyze its running time. For simplicity you can assume that all pi and all vi are distinct and that at no point in time three jet skis are at exactly the same position.
I can't find an algorithm with time complexity better than O(n^2).




The location of each jet ski, starting at position
pand travels at rater, can be written as the functionf(t) = p + r * t. These functions are lines.You can use Convex Hull Trick or Li Chao Tree to efficiently maintain which of the lines gives the maximal value at arbitrary values of
t. Without knowing the exact format of your output it is hard to say which is the best to use.