CF1256C.Platforms Jumping

普及+/提高

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

There is a river of width nn. The left bank of the river is cell 00 and the right bank is cell n+1n + 1 (more formally, the river can be represented as a sequence of n+2n + 2 cells numbered from 00 to n+1n + 1). There are also mm wooden platforms on a river, the ii-th platform has length cic_i (so the ii-th platform takes cic_i consecutive cells of the river). It is guaranteed that the sum of lengths of platforms does not exceed nn.

You are standing at 00 and want to reach n+1n+1 somehow. If you are standing at the position xx, you can jump to any position in the range [x+1;x+d][x + 1; x + d]. However you don't really like the water so you can jump only to such cells that belong to some wooden platform. For example, if d=1d=1, you can jump only to the next position (if it belongs to the wooden platform). You can assume that cells 00 and n+1n+1 belong to wooden platforms.

You want to know if it is possible to reach n+1n+1 from 00 if you can move any platform to the left or to the right arbitrary number of times (possibly, zero) as long as they do not intersect each other (but two platforms can touch each other). It also means that you cannot change the relative order of platforms.

Note that you should move platforms until you start jumping (in other words, you first move the platforms and then start jumping).

For example, if n=7n=7, m=3m=3, d=2d=2 and c=[1,2,1]c = [1, 2, 1], then one of the ways to reach 88 from 00 is follow:

The first example: n=7n=7.

有一条宽度为 nn 的河流。河流的左岸是第 00 号格子,右岸是第 n+1n + 1 号格子(更准确地说,整条河流可表示为编号从 00 到 n+1n + 1 的共 n+2n + 2 个格子组成的序列)。河上还有 mm 块木制平台,其中第 ii 块平台长度为 cic_i(即它占据河流中 cic_i 个连续的格子)。保证所有平台长度之和不超过 nn。

你起始于位置 00,希望以某种方式到达位置 n+1n+1。若你当前位于位置 xx,则你可以跳跃至区间 [x+1, x+d][x + 1,\, x + d] 内的任意位置。但你不喜水,因此只能跳到属于某块木制平台的格子上。例如,当 d=1d = 1 时,你只能跳到下一个位置(前提是该位置属于某块木制平台)。可假设格子 00 和 n+1n+1 均属于木制平台。

现在的问题是:在允许将任意平台向左或向右移动任意次数(包括零次)的前提下,能否从 00 到达 n+1n+1?移动需满足平台之间互不重叠(但可以相邻),且平台的相对顺序不可改变。

注意:你必须先完成所有平台的移动(即确定各平台最终位置),然后才开始跳跃。

例如,当 n=7n=7、m=3m=3、d=2d=2、c=[1,2,1]c = [1, 2, 1] 时,存在一种从 00 到达 88 的方案,如下图所示:

第一个例子:n=7n=7。

输入格式

The first line of the input contains three integers nn, mm and dd (1≤n,m,d≤1000,m≤n1 \le n, m, d \le 1000, m \le n) — the width of the river, the number of platforms and the maximum distance of your jump, correspondingly.

The second line of the input contains mm integers c1,c2,…,cmc_1, c_2, \dots, c_m (1≤ci≤n,∑i=1mci≤n1 \le c_i \le n, \sum\limits_{i=1}^{m} c_i \le n), where cic_i is the length of the ii-th platform.

输入的第一行包含三个整数 nn、mm 和 dd(1≤n,m,d≤10001 \le n, m, d \le 1000,且 m≤nm \le n),分别表示河流的宽度、平台的数量以及你单次跳跃的最大距离。

输入的第二行包含 mm 个整数 c1,c2,…,cmc_1, c_2, \dots, c_m(1≤ci≤n1 \le c_i \le n,且 ∑i=1mci≤n\sum\limits_{i=1}^{m} c_i \le n),其中 cic_i 表示第 ii 个平台的长度。

输出格式

If it is impossible to reach n+1n+1 from 00, print NO in the first line. Otherwise, print YES in the first line and the array aa of length nn in the second line — the sequence of river cells (excluding cell 00 and cell n+1n + 1).

If the cell ii does not belong to any platform, aia_i should be 00. Otherwise, it should be equal to the index of the platform (11-indexed, platforms are numbered from 11 to mm in order of input) to which the cell ii belongs.

Note that all aia_i equal to 11 should form a contiguous subsegment of the array aa of length c1c_1, all aia_i equal to 22 should form a contiguous subsegment of the array aa of length c2c_2, ..., all aia_i equal to mm should form a contiguous subsegment of the array aa of length cmc_m. The leftmost position of 22 in aa should be greater than the rightmost position of 11, the leftmost position of 33 in aa should be greater than the rightmost position of 22, ..., the leftmost position of mm in aa should be greater than the rightmost position of m−1m-1.

See example outputs for better understanding.

如果无法从 00 到达 n+1n+1,则在第一行输出 NO。否则,在第一行输出 YES,并在第二行输出长度为 nn 的数组 aa —— 表示河流中各格子(不包括格子 00 和格子 n+1n + 1)所属的平台编号。

若格子 ii 不属于任何平台,则 aia_i 应为 00;否则,aia_i 应等于该格子所属平台的编号(从 11 开始编号,平台按输入顺序依次编号为 11 至 mm)。

注意:所有值为 11 的 aia_i 必须构成数组 aa 中一个长度为 c1c_1 的连续子段;所有值为 22 的 aia_i 必须构成数组 aa 中一个长度为 c2c_2 的连续子段;……;所有值为 mm 的 aia_i 必须构成数组 aa 中一个长度为 cmc_m 的连续子段。此外,aa 中数字 22 的最左位置必须严格大于数字 11 的最右位置,数字 33 的最左位置必须严格大于数字 22 的最右位置,……,数字 mm 的最左位置必须严格大于数字 m−1m-1 的最右位置。

参见样例输出以获得更清晰的理解。

输入输出样例

  • 输入#1

    7 3 2
    1 2 1

    输出#1

    YES
    0 1 0 2 2 0 3
  • 输入#2

    10 1 11
    1

    输出#2

    YES
    0 0 0 0 0 0 0 0 0 1
  • 输入#3

    10 1 5
    2

    输出#3

    YES
    0 0 0 0 1 1 0 0 0 0

说明/提示

Consider the first example: the answer is [0,1,0,2,2,0,3][0, 1, 0, 2, 2, 0, 3]. The sequence of jumps you perform is 0→2→4→5→7→80 \rightarrow 2 \rightarrow 4 \rightarrow 5 \rightarrow 7 \rightarrow 8.

Consider the second example: it does not matter how to place the platform because you always can jump from 00 to 1111.

Consider the third example: the answer is [0,0,0,0,1,1,0,0,0,0][0, 0, 0, 0, 1, 1, 0, 0, 0, 0]. The sequence of jumps you perform is 0→5→6→110 \rightarrow 5 \rightarrow 6 \rightarrow 11.

考虑第一个例子:答案为 [0,1,0,2,2,0,3][0, 1, 0, 2, 2, 0, 3]。你执行的跳跃序列为 0→2→4→5→7→80 \rightarrow 2 \rightarrow 4 \rightarrow 5 \rightarrow 7 \rightarrow 8。

考虑第二个例子:平台如何放置无关紧要,因为你总能从 00 直接跳到 1111。

考虑第三个例子:答案为 [0,0,0,0,1,1,0,0,0,0][0, 0, 0, 0, 1, 1, 0, 0, 0, 0]。你执行的跳跃序列为 0→5→6→110 \rightarrow 5 \rightarrow 6 \rightarrow 11。

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

首页