Falling Portals
시간 제한2초메모리 제한512 MB
세계 i는 속도 i로 아래로 떨어지고, 높이가 같아지면 소가 다른 세계로 이동한다. i에서 Q_i로 가는 최단 시간을 기약분수로 구하거나 불가능하면 -1을 출력한다.
문제
There are () worlds, each with a portal. Initially, world (for ) is at -coordinate , and -coordinate (). There is also a cow on each world. At time , all -coordinates are distinct and the worlds start falling: world moves continuously in the negative- direction at a speed of units per second.
At any time when two worlds are at the same -coordinate (possibly a fractional time), the portals "align", meaning that a cow on one of the worlds can choose to travel instantaneously to the other world.
For each , the cow on world wants to travel to world (). Help each cow determine how long her journey will take, if she travels optimally.
Each query output should be a fraction where and are positive and relatively prime integers, or if it the journey is impossible.
입력
The first line of input contains a single integer
The next line contains space-separated integers
The next line contains space-separated integers
출력
Print lines, the -th of which contains the journey length for cow
힌트
Consider the answer for the cow originally on world 2. At time worlds 1 and 2 align, so the cow can travel to world 1. At time worlds 1 and 3 align, so the cow can travel to world 3.