#P1088. [NOIP 2004 普及组] 火星人

    ID: 88 远端评测题 1000ms 125MiB 尝试: 2 已通过: 2 难度: 3 上传者: 标签>模拟搜索数学2004NOIp 普及组排序

[NOIP 2004 普及组] 火星人

Description

Humans have finally set foot on Mars and met the mysterious Martians. Humans and Martians cannot understand each other's language, but our scientists invented a way to communicate using numbers. The method is as follows: first, the Martian tells the human scientist a very large number. After deciphering its meaning, the scientist adds a very small number to it and tells the result to the Martian as the human's reply.

Martians represent numbers in a very simple way—by bending their fingers. A Martian has only one hand, but this hand has thousands upon thousands of fingers arranged in a line, numbered 1,2,3,1,2,3,\cdots. Any two fingers can be swapped arbitrarily, and this is how they count.

A Martian demonstrated finger counting using a human hand. If the five fingers—thumb, index, middle, ring, and little finger—are numbered 1,2,3,41,2,3,4 and 55, then when they are in normal order, they form the 55-digit number 1234512345. If you swap the ring and little finger, you get 1235412354. If you completely reverse the order of the five fingers, you get 5432154321. Among all 120120 possible 55-digit numbers that can be formed, 1234512345 is the smallest and represents 11; 1235412354 is the second smallest and represents 22; 5432154321 is the largest and represents 120120. The table below shows the 66 possible 33-digit numbers when there are only 33 fingers, and the numbers they represent:

Three-digit number Represented number
123123 11
132132 22
213213 33
231231 44
312312 55
321321 66

Now you have the honor of being the first human to communicate with a Martian. A Martian will show you his fingers, and the scientists will tell you a small number to add. Your task is to add the number represented by the Martian’s fingers to the number given by the scientists, and then rearrange the Martian’s fingers according to the result. The input guarantees that the result will not exceed the range representable by the Martian’s fingers.

Input Format

There are three lines.
The first line contains a positive integer NN, the number of the Martian’s fingers (1N100001 \le N \le 10000).
The second line contains a positive integer MM, the small integer to add (1M1001 \le M \le 100).
The third line contains a permutation of the NN integers from 11 to NN, separated by spaces, representing the order of the Martian’s fingers.

Output Format

Output NN integers, the new order of the Martian’s fingers after the change. Separate adjacent numbers with a single space, and do not print extra spaces.

5
3
1 2 3 4 5

1 2 4 5 3

Hint

For 30%30\% of the testdata, N15N \le 15.
For 60%60\% of the testdata, N50N \le 50.
For 100%100\% of the testdata, N10000N \le 10000.

NOIP 2004 Junior Problem 4.

Translated by ChatGPT 5