codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

1256C.md (3919B)


      1 Source: https://codeforces.com/problemset/problem/1256/C
      2 
      3 C. Platforms Jumping
      4 
      5 time limit per test
      6 
      7 1 second
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 There is a river of width $n$. The left bank of the river is cell $0$ and the right bank is cell $n + 1$ (more formally, the river can be represented as a sequence of $n + 2$ cells numbered from $0$ to $n + 1$). There are also $m$ wooden platforms on a river, the $i$-th platform has length $c_i$ (so the $i$-th platform takes $c_i$ consecutive cells of the river). It is guaranteed that the sum of lengths of platforms does not exceed $n$.
     22 
     23 You are standing at $0$ and want to reach $n+1$ somehow. If you are standing at the position $x$, you can jump to any position in the range $[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=1$, you can jump only to the next position (if it belongs to the wooden platform). You can assume that cells $0$ and $n+1$ belong to wooden platforms.
     24 
     25 You want to know if it is possible to reach $n+1$ from $0$ 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.
     26 
     27 Note that you should move platforms until you start jumping (in other words, you first move the platforms and then start jumping).
     28 
     29 For example, if $n=7$, $m=3$, $d=2$ and $c = [1, 2, 1]$, then one of the ways to reach $8$ from $0$ is follow:
     30 
     31  ![](https://espresso.codeforces.com/fca3ef9d25f4bdfaee1eb4b454993ba831664bd3.png) The first example: $n=7$.
     32 
     33 Input
     34 
     35 The first line of the input contains three integers $n$, $m$ and $d$ ($1 \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.
     36 
     37 The second line of the input contains $m$ integers $c_1, c_2, \dots, c_m$ ($1 \le c_i \le n, \sum\limits_{i=1}^{m} c_i \le n$), where $c_i$ is the length of the $i$-th platform.
     38 
     39 Output
     40 
     41 If it is impossible to reach $n+1$ from $0$, print NO in the first line. Otherwise, print YES in the first line and the array $a$ of length $n$ in the second line — the sequence of river cells (excluding cell $0$ and cell $n + 1$).
     42 
     43 If the cell $i$ does not belong to any platform, $a_i$ should be $0$. Otherwise, it should be equal to the index of the platform ($1$-indexed, platforms are numbered from $1$ to $m$ in order of input) to which the cell $i$ belongs.
     44 
     45 Note that all $a_i$ equal to $1$ should form a contiguous subsegment of the array $a$ of length $c_1$, all $a_i$ equal to $2$ should form a contiguous subsegment of the array $a$ of length $c_2$, ..., all $a_i$ equal to $m$ should form a contiguous subsegment of the array $a$ of length $c_m$. The leftmost position of $2$ in $a$ should be greater than the rightmost position of $1$, the leftmost position of $3$ in $a$ should be greater than the rightmost position of $2$, ..., the leftmost position of $m$ in $a$ should be greater than the rightmost position of $m-1$.
     46 
     47 See example outputs for better understanding.
     48 
     49 Examples
     50 
     51 Input
     52 
     53 ```
     54 7 3 2
     55 1 2 1
     56 ```
     57 
     58 Output
     59 
     60 ```
     61 YES
     62 0 1 0 2 2 0 3
     63 ```
     64 
     65 Input
     66 
     67 ```
     68 10 1 11
     69 1
     70 ```
     71 
     72 Output
     73 
     74 ```
     75 YES
     76 0 0 0 0 0 0 0 0 0 1
     77 ```
     78 
     79 Input
     80 
     81 ```
     82 10 1 5
     83 2
     84 ```
     85 
     86 Output
     87 
     88 ```
     89 YES
     90 0 0 0 0 1 1 0 0 0 0
     91 ```
     92 
     93 Note
     94 
     95 Consider the first example: the answer is $[0, 1, 0, 2, 2, 0, 3]$. The sequence of jumps you perform is $0 \rightarrow 2 \rightarrow 4 \rightarrow 5 \rightarrow 7 \rightarrow 8$.
     96 
     97 Consider the second example: it does not matter how to place the platform because you always can jump from $0$ to $11$.
     98 
     99 Consider the third example: the answer is $[0, 0, 0, 0, 1, 1, 0, 0, 0, 0]$. The sequence of jumps you perform is $0 \rightarrow 5 \rightarrow 6 \rightarrow 11$.