Codeforces Global Round 29 (Div. 1 + Div. 2)
A
Shortest Increasing Path
Codeforces
800
原题
←B →
翻译中…

You are at $(0, 0)$ in a rectangular grid and want to go to $(x, y)$.

翻译中…

In order to do so, you are allowed to perform a sequence of steps.

翻译中…

Each step consists of moving a positive integer amount of length in the positive direction of either the $x$ or the $y$ axis.

翻译中…

The first step must be along the $x$ axis, the second along the $y$ axis, the third along the $x$ axis, and so on. Formally, if we number steps from one in the order they are done, then odd-numbered steps must be along the $x$ axis and even-numbered steps must be along the $y$ axis.

翻译中…

Additionally, each step must have a length strictly greater than the length of the previous one.

翻译中…

Output the minimum number of steps needed to reach $(x, y)$, or $-1$ if it is impossible.

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^4$). The description of the test cases follows.

翻译中…

The first and only line of each case contains two integers $x$ and $y$ ($1 \le x, y \le 10^9$).

翻译中…

Output

翻译中…

For each test case, output the minimum number of steps to reach $(x, y)$ or $-1$ if it is impossible.

翻译中…

Note

翻译中…
翻译中…

In the second test case, you can move to $(5, 0)$ by moving $5$ along the $x$ axis and then to $(5, 6)$ by moving $6$ along the $y$ axis.

翻译中…

image

翻译中…

In the third test case, you can move to $(1, 0)$, then to $(1, 2)$, and finally to $(4, 2)$.

翻译中…

image

翻译中…

In the fourth test case, reaching $(1, 1)$ is impossible since after moving to $(1, 0)$ along the $x$ axis, you are forced to move at least $2$ along the $y$ axis.

翻译中…

样例

Input #1
10
1 2
5 6
4 2
1 1
2 1
3 3
5 1
5 4
752 18572
95152 2322
Output #1
2
2
3
-1
-1
-1
-1
-1
2
3
InputCopy OutputCopy
题目信息
题号
2147A
时间限制
1 s
内存限制
256 MB
标签
构造
贪心

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。