#P10217. [省选联考 2024] 季风

[省选联考 2024] 季风

Background

Little X, who lives on a 2D plane, is going to visit Little Y. However, due to climate changes, a monsoon is blowing on the plane. Little X wants to know, under the influence of the monsoon, at least how many days it will take to reach Little Y’s home. Since Little X is also seeing this strange situation for the first time, please ask you, who are skilled in algorithms, to help.

Problem Description

Given n,k,x,yn, k, x, y and 2n2n integers x0,y0,x1,y1,,xn1,yn1x_0, y_0, x_1, y_1, \dots, x_{n-1}, y_{n-1}.

Find the minimum non-negative integer mm such that there exist 2m2m real numbers x0,y0,x1,y1,,xm1,ym1x_0', y_0', x_1', y_1', \dots, x_{m-1}', y_{m-1}' satisfying the following conditions, or report that no such mm exists:

  • $\sum \limits_{i=0}^{m-1} (x_i' + x_{i \bmod n}) = x$;
  • $\sum \limits_{i=0}^{m-1} (y_i' + y_{i \bmod n}) = y$;
  • 0im1,xi+yik\forall 0 \leq i \leq m-1, |x_i'| + |y_i'| \leq k.

In particular, when m=0m = 0, both i=0m1(xi+ximodn)\sum \limits_{i=0}^{m-1} (x_i' + x_{i \bmod n}) and i=0m1(yi+yimodn)\sum \limits_{i=0}^{m-1} (y_i' + y_{i \bmod n}) are considered to be 00.

Input Format

This problem has multiple test cases. The first line contains an integer TT denoting the number of test cases.

For each test case,

  • The first line contains four integers n,k,x,yn, k, x, y;
  • The next nn lines contain two integers each; the ii-th line contains xi1,yi1x_{i-1}, y_{i-1}.

Output Format

For each test case, output one integer per line. If there exists an mm satisfying the statement, output the minimum possible value; otherwise output 1-1.

4
1 2 2 2
1 1
1 2 -2 -2
1 1
1 2 0 0
1 1
2 100000000 100000000 100000000
-99999999 0
-100000000 0
1
-1
0
399999999

Hint

[Sample 1 Explanation]

This sample contains four test cases.

  • For the first test case, take m=1m = 1, (x0,y0)=(1,1)(x_0', y_0') = (1, 1), which satisfies the conditions. It can be proven that no smaller mm can satisfy the conditions;
  • For the second test case, it can be proven that there is no non-negative integer mm that satisfies the conditions;
  • For the third test case, take m=0m = 0, which satisfies the conditions. It can be proven that no smaller mm can satisfy the conditions.

[Sample 2]

See the attached wind2.in/ans.

This sample contains eighty test cases. All testdata satisfy n=1n = 1, where testdata 1201 \sim 20 satisfy Special Property A, 214021 \sim 40 satisfy Special Property B, and 416041 \sim 60 satisfy Special Property C.

[Sample 3]

See the attached wind3.in/ans.

This sample contains sixty test cases. All testdata satisfy n=200n = 200, where testdata 1201 \sim 20 satisfy Special Property A, and 214021 \sim 40 satisfy Special Property B.

[Subtasks]

Let n\sum n be the sum of nn over all test cases within a single test point. For all testdata:

  • 1T5×1041 \leq T \leq 5 \times 10^4;
  • 1n1051 \leq n \leq 10^5, 1n1061 \leq \sum n \leq 10^6;
  • 0x,y,xi,yi,k1080 \leq |x|, |y|, |x_i|, |y_i|, k \leq 10^8.
Test Point ID nn \leq n\sum n \leq Special Property
11 11 300300 A
22 B
33 C
44 None
55 200200 50005000 A
66 B
77 None
88 10410^4 10510^5 A
99 B
1010 10510^5 10610^6 None
  • Special Property A: 0in1\forall 0 \leq i \leq n-1, xi+yik|x_i| + |y_i| \leq k;
  • Special Property B: k=0k = 0;
  • Special Property C: x0=y0=0x_0 = y_0 = 0.

[Hint]

The input file for this problem is large. Please use a faster input method.

Translated by ChatGPT 5