QOJ.ac

QOJ

Time Limit: 1.0 s Memory Limit: 256 MB Total points: 100 Hackable ✓

#20287. 細菌の培養

Statistics

2 つの整数列 $a_1, a_2, \ldots, a_n$ と $b_1, b_2, \ldots, b_n$、および整数 $M$ が与えられます。

1 回の操作では、2 つの整数 $l$ と $r$ ($1 \le l \le r \le n$) を選びます。すべての $i$ ($l \le i \le r$) について、$a_i$ を $\min(2 \cdot a_i, M)$ に置き換えます。

$a$ を $b$ に変えるために必要な操作回数の最小値を求めてください。不可能なら $-1$ を出力してください。

入力

各入力ファイルには複数のテストケースが含まれます。最初の行にはテストケースの数 $T$ ($1 \le T \le 10^4$) が与えられます。その後に各テストケースの記述が続きます。

各テストケースの最初の行には、2 つの整数 $n$ と $M$ ($1 \le n \le 2 \cdot 10^5$, $1 \le M \le 10^9$) が与えられます。

2 行目には、初期の数列を表す $n$ 個の整数 $a_1, a_2, \ldots, a_n$ ($0 \le a_i \le M$) が与えられます。

3 行目には、目標の数列を表す $n$ 個の整数 $b_1, b_2, \ldots, b_n$ ($0 \le b_i \le M$) が与えられます。

すべてのテストケースにわたる $n$ の合計は $2 \cdot 10^5$ 以下であることが保証されます。

出力

各テストケースについて、$a$ を $b$ に変えるために必要な操作回数の最小値を出力してください。不可能なら、整数 $-1$ を 1 つ出力してください。

入出力例

入力 1

2
5 10
1 3 0 6 2
4 10 0 10 8
3 12
3 4 0
12 10 0

出力 1

2
-1

注記

最初のテストケースでは、区間 $[1, 5]$ に操作を 2 回適用します。1 回目の操作後、数列は $[2, 6, 0, 10, 4]$ となり、2 回目の操作後には $[4, 10, 0, 10, 8]$ となるので、答えは $2$ です。

2 番目のテストケースでは、何回操作を行っても 2 番目の要素は $4$、$8$、$12$ のいずれかにしかならず、$10$ にはなりません。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.