| TheForces Round #21 (EDU-Forces) |
|---|
| Finished |
There are $$$n$$$ circular positions on the table in the sushi restaurant.
Initially, there are $$$x_i$$$ pieces of sushi in the plate at position $$$i$$$.Every second,the plate at position $$$i$$$ will be put into $$$a_i$$$ pieces of sushi.Then,the plates will revolve.
Formally:
If for each position,the number of sushi is a multiple of $$$k$$$,customers will be happy.
Find the minimum waiting time to make customers happy.If no solution,output $$$-1$$$ instead.
The first line of input will contain a single integer $$$t(t \leq 10^5)$$$, denoting the number of test cases.
Each test case contains three lines.
The first line contains two space-separated integers $$$n$$$,$$$k(1\leq n \leq 4*10^5,1\leq k \leq 10^9)$$$.
The next line contains $$$n$$$ integers:$$$x_1$$$,$$$x_2$$$,...$$$x_n(1 \leq x_i \leq 10^9)$$$.
The next line contains $$$n$$$ integers:$$$a_1$$$,$$$a_2$$$,...$$$a_n(1 \leq a_i \leq 10^9)$$$.
It's guaranteed that the sum of $$$n$$$ over all test cases will not exceed $$$4*10^5$$$.
For each test case,output on a new line — the minimum waiting time to make customers happy.If no solution,output $$$-1$$$ instead.
53 21 2 31 2 24 41 1 1 11 1 1 14 81 3 5 72 4 6 84 33 6 9 121 1 1 14 61 6 1 26 7 7 6
2 3 -1 0 10
Test case $$$1$$$:
Note $$$p_i$$$ as the number of sushi in the plate currently in position $$$i$$$.
Initially:$$$p=[1,2,3]$$$;
The $$$1_{st}$$$ second:$$$p=[5,2,4]$$$;
The $$$2_{nd}$$$ second:$$$p=[6,6,4]$$$.
After $$$2$$$ seconds, all numbers are multiples of $$$k=2$$$, so the answer is $$$2$$$.
| Name |
|---|


