#abc301b. B - Fill the Gaps
B - Fill the Gaps
Score : points
问题描述
我们有一个长度为 的正整数序列:。其中任意两个相邻项的值都不同。
让我们按照以下步骤向该序列中插入一些数字。
- 如果 中每一对相邻项之间的绝对差均为 ,则结束该过程。
- 让 成为 开头附近绝对差不为 的相邻项对。
- 若 ,在 和 之间插入 。
- 若 ,在 和 之间插入 。
- 返回步骤 1。
当过程结束时,打印出该序列。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
We have a sequence of length consisting of positive integers: . Any two adjacent terms have different values.
Let us insert some numbers into this sequence by the following procedure.
- If every pair of adjacent terms in has an absolute difference of , terminate the procedure.
- Let be the pair of adjacent terms nearest to the beginning of whose absolute difference is not .
- If , insert between and .
- If , insert between and .
- Return to step 1.
Print the sequence when the procedure ends.
Constraints
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
Output
Print the terms in the sequence when the procedure ends, separated by spaces.
Sample Input 1
4
2 5 1 2
Sample Output 1
2 3 4 5 4 3 2 1 2
The initial sequence is . The procedure goes as follows.
- Insert between the first term and the second term , making the sequence .
- Insert between the fourth term and the fifth term , making the sequence .
Sample Input 2
6
3 4 5 6 5 4
Sample Output 2
3 4 5 6 5 4
No insertions may be performed.
update @ 2024/3/10 08:26:44