Two Rabbits
Time limit1sMemory limit256 MB
Two rabbits hop toward each other by fixed distances each second; find the time they land on the same point, or -1 if they never do.
- Level
Easy2 of 10
- Topics
- Math, Implementation
- Solved
- No attempts yet
문제
Tired of taking part in too many Codeforces rounds, Gildong decided to rest in a park. He sat down on a bench, and soon he saw two rabbits hopping around. One of the rabbits was taller than the other.
The two rabbits were hopping towards each other. Their positions are integer coordinates on a horizontal line. The taller rabbit is at position , and the shorter rabbit is at position (). Every second, each rabbit hops to another position. The taller rabbit hops in the positive direction by , and the shorter rabbit hops in the negative direction by .

For example, let , , , and . After 1 second, the rabbits are at positions 2 and 7. After 2 seconds, both rabbits are at position 4.
Gildong wants to know whether the two rabbits will ever be at the same position at the same moment. If they will, how many seconds will it take? Find the moment (in seconds) after which the rabbits are at the same point.
입력
The first line contains the number of test cases ().
Each test case is one line with four integers , , , . They are the current position of the taller rabbit, the current position of the shorter rabbit, the hop distance of the taller rabbit, and the hop distance of the shorter rabbit, respectively (, ).
출력
For each test case, print one integer: the number of seconds the two rabbits take to be at the same position.
If the two rabbits never be at the same position at the same time, print .
힌트
The first case is explained in the statement. In the second case, after 1 second the rabbits are at positions 3 and 7. After 2 seconds they are at positions 6 and 4. After that, the distance between them only grows, so they never meet.