QOJ.ac

QOJ

時間限制: 7 s 記憶體限制: 1024 MB 總分: 100 可 Hack ✓

#14235. 扶摇直上

统计

Steve's Retreat

Steve 在他家周围的多座山上建立了 $n$ 个基地,他家位于 1 号山。他想使用鞘翅(elytra)从一个基地飞到另一个基地,并到达位于 $x$ 号山的度假屋。不幸的是,从一个基地飞到另一个基地需要时间,而且他只能从较高的山飞往较低的山!如果两座山的高度相同,他也可以在它们之间飞行。

幸运的是,他可以使用烟花,这使他也可以从较低的山前往较高的山!然而,他的烟花不多,因此在整个旅程中,使用烟花向上飞行的累计海拔高度差不能超过 $k$。请帮助 Steve 计算他到达度假屋的最快时间,或者确定他无法到达!

输入格式

第一行包含三个空格分隔的整数 $n$、$x$ 和 $k$($1 \le n, k \le 100$,$1 \le x \le n$),分别表示基地的数量、度假屋的位置以及烟花的限制额度。

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

接下来的 $n$ 行,每行包含 $n$ 个整数。其中第 $i$ 行的第 $j$ 个整数表示从第 $i$ 个基地前往第 $j$ 个基地所需的时间。第 $i$ 行的第 $i$ 个数始终为 0。两山之间的旅行时间不会超过 $1\,000$。

输出格式

如果 Steve 能够到达他的度假屋,输出一个整数,表示 Steve 到达位于基地 $x$ 的度假屋所需的最短时间。如果他无法到达度假屋,输出 $-1$。

样例

输入样例 1

3 3 3
3 6 2
0 1 10
10 0 1
10 10 0

输出样例 1

2

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.