1759C.md (1977B)
1 Source: https://codeforces.com/problemset/problem/1759/C 2 3 C. Thermostat 4 5 time limit per test 6 7 1 second 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 standard input 16 17 output 18 19 standard output 20 21 Vlad came home and found out that someone had reconfigured the old thermostat to the temperature of $a$. 22 23 The thermostat can only be set to a temperature from $l$ to $r$ inclusive, the temperature cannot change by less than $x$. Formally, in one operation you can reconfigure the thermostat from temperature $a$ to temperature $b$ if $|a - b| \ge x$ and $l \le b \le r$. 24 25 You are given $l$, $r$, $x$, $a$ and $b$. Find the minimum number of operations required to get temperature $b$ from temperature $a$, or say that it is impossible. 26 27 Input 28 29 The first line of input data contains the single integer $t$ ($1 \le t \le 10^4$) — the number of test cases in the test. 30 31 The descriptions of the test cases follow. 32 33 The first line of each case contains three integers $l$, $r$ and $x$ ($-10^9 \le l \le r \le 10^9$, $1 \le x \le 10^9$) — range of temperature and minimum temperature change. 34 35 The second line of each case contains two integers $a$ and $b$ ($l \le a, b \le r$) — the initial and final temperatures. 36 37 Output 38 39 Output $t$ numbers, each of which is the answer to the corresponding test case. If it is impossible to achieve the temperature $b$, output -1, otherwise output the minimum number of operations. 40 41 Example 42 43 Input 44 45 ``` 46 10 47 48 3 5 6 49 50 3 3 51 52 0 15 5 53 54 4 5 55 56 0 10 5 57 58 3 7 59 60 3 5 6 61 62 3 4 63 64 -10 10 11 65 66 -5 6 67 68 -3 3 4 69 70 1 0 71 72 -5 10 8 73 74 9 2 75 76 1 5 1 77 78 2 5 79 80 -1 4 3 81 82 0 2 83 84 -6 3 6 85 86 -1 -4 87 ``` 88 89 Output 90 91 ``` 92 0 93 2 94 3 95 -1 96 1 97 -1 98 3 99 1 100 3 101 -1 102 ``` 103 104 Note 105 106 In the first example, the thermostat is already set up correctly. 107 108 In the second example, you can achieve the desired temperature as follows: $4 \rightarrow 10 \rightarrow 5$. 109 110 In the third example, you can achieve the desired temperature as follows: $3 \rightarrow 8 \rightarrow 2 \rightarrow 7$. 111 112 In the fourth test, it is impossible to make any operation.