Codeforces Round 480 (Div. 2)
C
Posterized
Codeforces
1700
原题
← BD →
翻译中…

Professor Ibrahim has prepared the final homework for his algorithm’s class. He asked his students to implement the Posterization Image Filter.

翻译中…

Their algorithm will be tested on an array of integers, where the $i$-th integer represents the color of the $i$-th pixel in the image. The image is in black and white, therefore the color of each pixel will be an integer between 0 and 255 (inclusive).

翻译中…

To implement the filter, students are required to divide the black and white color range [0, 255] into groups of consecutive colors, and select one color in each group to be the group’s key. In order to preserve image details, the size of a group must not be greater than $k$, and each color should belong to exactly one group.

翻译中…

Finally, the students will replace the color of each pixel in the array with that color’s assigned group key.

翻译中…

To better understand the effect, here is an image of a basking turtle where the Posterization Filter was applied with increasing $k$ to the right.

翻译中…

image

翻译中…

To make the process of checking the final answer easier, Professor Ibrahim wants students to divide the groups and assign the keys in a way that produces the lexicographically smallest possible array.

翻译中…

Input

翻译中…

The first line of input contains two integers $n$ and $k$ ($1 \leq n \leq 10^5$, $1 \leq k \leq 256$), the number of pixels in the image, and the maximum size of a group, respectively.

翻译中…

The second line contains $n$ integers $p_1, p_2, \dots, p_n$ ($0 \leq p_i \leq 255$), where $p_i$ is the color of the $i$-th pixel.

翻译中…

Output

翻译中…

Print $n$ space-separated integers; the lexicographically smallest possible array that represents the image after applying the Posterization filter.

翻译中…

Note

翻译中…

One possible way to group colors and assign keys for the first sample:

翻译中…

Color $2$ belongs to the group $[0,2]$, with group key $0$.

翻译中…

Color $14$ belongs to the group $[12,14]$, with group key $12$.

翻译中…

Colors $3$ and $4$ belong to group $[3, 5]$, with group key $3$.

翻译中…

Other groups won't affect the result so they are not listed here.

翻译中…

样例

Input #1
4 3
2 14 3 4
Output #1
0 12 3 3
InputCopy OutputCopy
Input #2
5 2
0 2 1 255 254
Output #2
0 1 1 254 254
InputCopy OutputCopy
题目信息
题号
980C
时间限制
1 s
内存限制
256 MB
标签
博弈论
贪心

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。