308939: CF1601B. Frog Traveler
Memory Limit:512 MB
Time Limit:2 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
Frog Traveler
题意翻译
### 题目描述 青蛙在 $n$ 米深的井中。 对于每一个深度,有两个量 $a_i$ 和 $b_i$。 $a_i$ 表示在深度为 $i$ 米的时候可以往上跳的最高高度,就是说在深度为 $i$ 米的地方可以往上跳 $\left[0,a_i\right]$ 米。 $b_i$ 表示在深度为 $i$ 米的地方时会往下滑 $b_i$ 米。 青蛙每跳一次,就会下滑一次。 请求出青蛙最少跳几次可以跳出井(深度为 $0$ 米)。 ### 输入格式 第一行输入一个正整数 $n$ 表示井的深度。 第 $2$ 行输入 $n$ 个整数,第 $i$ 个整数表示 $a_i$,含义见题目描述。 第 $3$ 行输入 $n$ 个整数,第 $i$ 个整数表示 $b_i$,含义见题目描述。 ### 输出格式 如果青蛙可以跳出井,输出 $2$ 行,第一行一个正整数表示跳的最少次数 $k$,第二行输出 $k$ 个整数表示跳 $k$ 次之后(下滑前)青蛙位于的深度。 如果青蛙跳不出井,输出 `-1`。 ### 数据范围 $1\le n\le3\times10^5,0\le a_i\le i,0\le b_i\le n-i$。题目描述
Frog Gorf is traveling through Swamp kingdom. Unfortunately, after a poor jump, he fell into a well of $ n $ 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 $ x $ meters below ground level, then in one jump he can go up on any integer distance from $ 0 $ to $ a_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 $ 0 $ meters). And after jumping up to position $ x $ meters below ground level, he'll slip exactly $ b_x $ meters down while resting. Calculate the minimum number of jumps Gorf needs to reach ground level.输入输出格式
输入格式
The first line contains a single integer $ n $ ( $ 1 \le n \le 300\,000 $ ) — the depth of the well. The second line contains $ n $ integers $ a_1, a_2, \ldots, a_n $ ( $ 0 \le a_i \le i $ ), where $ a_i $ is the maximum height Gorf can jump from $ i $ meters below ground level. The third line contains $ n $ integers $ b_1, b_2, \ldots, b_n $ ( $ 0 \le b_i \le n - i $ ), where $ b_i $ is the distance Gorf will slip down if he takes a break on $ i $ meters below ground level.
输出格式
If Gorf can't reach ground level, print $ -1 $ . Otherwise, firstly print integer $ k $ — the minimum possible number of jumps. Then print the sequence $ d_1,\,d_2,\,\ldots,\,d_k $ where $ d_j $ is the depth Gorf'll reach after the $ j $ -th jump, but before he'll slip down during the break. Ground level is equal to $ 0 $ . If there are multiple answers, print any of them.
输入输出样例
输入样例 #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