QOJ.ac

QOJ

実行時間制限: 1 s メモリ制限: 1024 MB 満点: 100 ハック可能 ✓

#14236. 再次扶摇直上

統計

Steve 的度假屋

又一年过去了,Steve 想要再次前往他的度假屋!在他的房子周围仍然有 $n$ 个位于山上的基地。Steve 当前位于第 $1$ 座山,而他的度假屋位于第 $x$ 座山。

今年,生态群系滑雪公司(Biomes Ski Corporation)在各座山之间建造了许多滑雪缆车。Steve 想要乘坐滑雪缆车,希望这能比坐飞机欣赏到更美丽的风景。Steve 知道每座山都有一个危险值 $d_i$,这意味着一座高度为 $h_i$ 的山只有在满足 $\text{abs}(h_i - h_j) \le d_j$ 时,才能通过滑雪缆车与高度为 $h_j$ 的山相连。然而,由于预算有限,他们只建造了向下的滑雪缆车。因此,从高度为 $h_i$ 的山出发,他只能前往危险值为 $d_j$ 且高度为 $h_j$ 的山,前提是满足 $0 \le h_i - h_j \le d_j$。

每部滑雪缆车在两座山之间的运行时间均为 $t$。请帮助 Steve 计算前往他的度假屋所需的最短时间,或者确定他无法通过滑雪缆车到达他的度假屋!

输入格式

第一行包含 $3$ 个空格分隔的整数 $n$、$x$ 和 $t$($1 \le n \le 10^5$,$1 \le x \le n$,$1 \le t \le 10^9$),分别表示基地的数量、度假屋所在的位置以及每部滑雪缆车的运行时间。

第二行包含 $n$ 个整数 $h_1, h_2, \dots, h_n$,其中 $h_i$($1 \le h_i \le 10^5$)表示第 $i$ 个基地所在山的高度。

第三行包含 $n$ 个整数 $d_1, d_2, \dots, d_n$,其中 $d_i$($1 \le d_i \le 10^5$)表示第 $i$ 个基地所在山的危险值。

输出格式

输出一个整数,表示 Steve 前往度假屋所需的最短时间。如果他无法通过滑雪缆车到达度假屋,则输出 -1

样例

输入样例 1

3 3 4
3 6 2
1 2 3

输出样例 1

4

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.