[CCC-HK 17S4] Cost
Difficulty Ratings Idea Creativity: 4/5 Techniques Used: 2/5 Implementation : 2/5 When I asked people how to solve this problem they said its treap, but when i asked for details they run away smh... It is not a treap problem... Statement You are moving in a Cartesian plane. At the beginning you are at $(0, 0)$, and your target is $(n, m)$. Once you are at $(x, y)$, you can move to the point $(x, y + 1)$ with the cost $A_x$, or move to the point $(x + 1, y)$ with the cost $B_y$. Given the sequences $A$ and $B$, your task is to find out the minimum cost from $(0, 0)$ to $(n, m)$. $n,m \le 1e6$ Solution So the problem is equivalent to having costs on each line and find shortest path. Obviously it is beneficial to walk on lines with small cost. Lets define $x_{min}$ to be the x-coordinate with smallest cost, and $y_{min}$ to be the y-coordinate with smallest cost (tiebreak arbitarily). Then, we can conclude that the optimal path passes through $(x_{min},y_{min})$. It is not h