#P6010. [USACO20JAN] Falling Portals P
[USACO20JAN] Falling Portals P
Description
There are worlds (), and each world has a portal. Initially, world (for ) is at -coordinate and -coordinate (). Each world also contains a cow. At time , all -coordinates are distinct, and then the worlds begin to fall: world moves along the negative -axis at a speed of units per second.
At any time, if two worlds have the same -coordinate at some moment (possibly at a non-integer time), their portals will “synchronize”, allowing a cow in one world to choose to instantly teleport to the other world.
For each , the cow in world wants to go to world (). Help each cow compute how much time it takes if she moves in the best possible way.
Each query should be output as a fraction , where and are coprime positive integers, or if it is impossible to reach.
Input Format
The first line contains an integer .
The next line contains space-separated integers .
The next line contains space-separated integers .
Output Format
Output lines. The -th line contains the travel time for cow .
4
3 5 10 2
3 3 2 1
7/2
7/2
5/1
-1
Hint
Sample Explanation
Consider the answer for the cow originally in world . At time , worlds and synchronize, so the cow can go to world . At time , worlds and synchronize, so the cow can go to world .
Subtasks
- Test points satisfy .
- Test points satisfy .
- Test points have no additional constraints.
Translated by ChatGPT 5
京公网安备 11011102002149号