CF1601B.Frog Traveler

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:512MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Frog Gorf is traveling through Swamp kingdom. Unfortunately, after a poor jump, he fell into a well of nn meters depth. Now Gorf is on the bottom of the well and has a long way up.

The surface of the well's walls vary in quality: somewhere they are slippery, but somewhere have convenient ledges. In other words, if Gorf is on xx meters below ground level, then in one jump he can go up on any integer distance from 00 to axa_x meters inclusive. (Note that Gorf can't jump down, only up).

Unfortunately, Gorf has to take a break after each jump (including jump on 00 meters). And after jumping up to position xx meters below ground level, he'll slip exactly bxb_x meters down while resting.

Calculate the minimum number of jumps Gorf needs to reach ground level.

青蛙戈尔夫正在穿越沼泽王国。不幸的是,一次糟糕的跳跃后,他掉进了一口深度为 nn 米的井中。现在戈尔夫位于井底,需要向上爬很长一段距离。

井壁表面质量不均:有些地方很滑,而有些地方则有便于攀爬的凸起。换言之,若戈尔夫当前位于地下 xx 米处,则他单次跳跃最多可向上移动 axa_x 米,且可选择任意介于 00 到 axa_x(含端点)之间的整数米数。(注意:戈尔夫不能向下跳,只能向上跳。)

不幸的是,戈尔夫每次跳跃后(包括跳跃高度为 00 米的情况)都必须休息。当他跳跃至地下 xx 米处并开始休息时,他会恰好向下滑落 bxb_x 米。

请计算戈尔夫到达地面所需的最少跳跃次数。

输入格式

The first line contains a single integer nn (1≤n≤300 0001 \le n \le 300\,000) — the depth of the well.

The second line contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (0≤ai≤i0 \le a_i \le i), where aia_i is the maximum height Gorf can jump from ii meters below ground level.

The third line contains nn integers b1,b2,…,bnb_1, b_2, \ldots, b_n (0≤bi≤n−i0 \le b_i \le n - i), where bib_i is the distance Gorf will slip down if he takes a break on ii meters below ground level.

第一行包含一个整数 nn(1≤n≤300 0001 \le n \le 300\,000)—— 表示井的深度。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(0≤ai≤i0 \le a_i \le i),其中 aia_i 表示 Gorf 在地下 ii 米处所能跳跃的最大高度。

第三行包含 nn 个整数 b1,b2,…,bnb_1, b_2, \ldots, b_n(0≤bi≤n−i0 \le b_i \le n - i),其中 bib_i 表示 Gorf 在地下 ii 米处休息时将向下滑落的距离。

输出格式

If Gorf can't reach ground level, print −1-1. Otherwise, firstly print integer kk — the minimum possible number of jumps.

Then print the sequence d1, d2, …, dkd_1,\,d_2,\,\ldots,\,d_k where djd_j is the depth Gorf'll reach after the jj-th jump, but before he'll slip down during the break. Ground level is equal to 00.

If there are multiple answers, print any of them.

如果戈尔夫无法到达地面,则输出 −1-1。否则,首先输出整数 kk —— 即最少可能的跳跃次数。

然后输出序列 d1, d2, …, dkd_1,\,d_2,\,\ldots,\,d_k,其中 djd_j 表示戈尔夫在第 jj 次跳跃后、但在休息期间向下滑落前所达到的深度。地面高度为 00。

若存在多个答案,输出任意一个即可。

输入输出样例

  • 输入#1

    3
    0 2 2
    1 1 0

    输出#1

    2
    1 0
  • 输入#2

    2
    1 1
    1 0

    输出#2

    -1
  • 输入#3

    10
    0 1 2 3 5 5 6 7 8 5
    9 8 7 1 5 4 3 2 0 0

    输出#3

    3
    9 4 0

说明/提示

In the first example, Gorf is on the bottom of the well and jump to the height 11 meter below ground level. After that he slip down by meter and stays on height 22 meters below ground level. Now, from here, he can reach ground level in one jump.

In the second example, Gorf can jump to one meter below ground level, but will slip down back to the bottom of the well. That's why he can't reach ground level.

In the third example, Gorf can reach ground level only from the height 55 meters below the ground level. And Gorf can reach this height using a series of jumps 10⇒9⇢9⇒4⇢510 \Rightarrow 9 \dashrightarrow 9 \Rightarrow 4 \dashrightarrow 5 where ⇒\Rightarrow is the jump and ⇢\dashrightarrow is slipping during breaks.

在第一个例子中,戈尔夫位于井底,跳跃后到达地面以下 11 米的高度。随后他下滑 11 米,停留在地面以下 22 米的高度。此时,他只需一次跳跃即可到达地面。

在第二个例子中,戈尔夫可以跳跃至地面以下 11 米处,但随后会滑回井底。因此他无法到达地面。

在第三个例子中,戈尔夫仅能从地面以下 55 米的高度起跳到达地面。而戈尔夫可通过一系列跳跃达到该高度:10⇒9⇢9⇒4⇢510 \Rightarrow 9 \dashrightarrow 9 \Rightarrow 4 \dashrightarrow 5,其中 ⇒\Rightarrow 表示跳跃,⇢\dashrightarrow 表示休息期间的下滑。

输入解题思路,AI测评打分。不知道怎么写?

首页