codeforces-scrape

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

218A.md (2367B)


      1 Source: https://codeforces.com/problemset/problem/218/A
      2 
      3 A. Mountain Scenery
      4 
      5 time limit per test
      6 
      7 2 seconds
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 stdin
     16 
     17 output
     18 
     19 stdout
     20 
     21 Little Bolek has found a picture with *n* mountain peaks painted on it. The *n* painted peaks are represented by a non-closed polyline, consisting of 2*n* segments. The segments go through 2*n* + 1 points with coordinates (1, *y*1), (2, *y*2), ..., (2*n* + 1, *y*2*n* + 1), with the *i*-th segment connecting the point (*i*, *y**i*) and the point (*i* + 1, *y**i* + 1). For any even *i* (2 ≤ *i* ≤ 2*n*) the following condition holds: *y**i* - 1 < *y**i* and *y**i* > *y**i* + 1.
     22 
     23 We shall call a vertex of a polyline with an even *x* coordinate a mountain peak.
     24 
     25  ![](https://espresso.codeforces.com/d3b6d2bc90cda6280dc17f9b20e84d691d149131.png)  The figure to the left shows the initial picture, the figure to the right shows what the picture looks like after Bolek's actions. The affected peaks are marked red, *k* = 2.  
     26 
     27 Bolek fancied a little mischief. He chose exactly *k* mountain peaks, rubbed out the segments that went through those peaks and increased each peak's height by one (that is, he increased the *y* coordinate of the corresponding points). Then he painted the missing segments to get a new picture of mountain peaks. Let us denote the points through which the new polyline passes on Bolek's new picture as (1, *r*1), (2, *r*2), ..., (2*n* + 1, *r*2*n* + 1).
     28 
     29 Given Bolek's final picture, restore the initial one.
     30 
     31 Input
     32 
     33 The first line contains two space-separated integers *n* and *k* (1 ≤ *k* ≤ *n* ≤ 100). The next line contains 2*n* + 1 space-separated integers *r*1, *r*2, ..., *r*2*n* + 1 (0 ≤ *r**i* ≤ 100) — the *y* coordinates of the polyline vertices on Bolek's picture.
     34 
     35 It is guaranteed that we can obtain the given picture after performing the described actions on some picture of mountain peaks.
     36 
     37 Output
     38 
     39 Print 2*n* + 1 integers *y*1, *y*2, ..., *y*2*n* + 1 — the *y* coordinates of the vertices of the polyline on the initial picture. If there are multiple answers, output any one of them.
     40 
     41 Examples
     42 
     43 Input
     44 
     45 ```
     46 3 2  
     47 0 5 3 5 1 5 2
     48 ```
     49 
     50 Output
     51 
     52 ```
     53 0 5 3 4 1 4 2
     54 ```
     55 
     56 Input
     57 
     58 ```
     59 1 1  
     60 0 2 0
     61 ```
     62 
     63 Output
     64 
     65 ```
     66 0 1 0
     67 ```