This page is still under construction.

Parts of this page are still being built. What you see may change.

Two Rabbits

Time limit1sMemory limit256 MB

Summary
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 xx, and the shorter rabbit is at position yy (x<yx<y). Every second, each rabbit hops to another position. The taller rabbit hops in the positive direction by aa, and the shorter rabbit hops in the negative direction by bb.

For example, let x=0x=0, y=10y=10, a=2a=2, and b=3b=3. 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 tt (1≤t≤10001 \le t \le 1000).

Each test case is one line with four integers xx, yy, aa, bb. 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 (0≤x<y≤1090 \le x < y \le 10^9, 1≤a,b≤1091 \le a,b \le 10^9).

출력

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 −1-1.

힌트

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.

Examples1

  1. Example 1

    Input
    5
    0 10 2 3
    0 10 3 3
    900000000 1000000000 1 9999999
    1 2 1 1
    1 3 1 1
    
    Expected output
    2
    -1
    10
    -1
    1