A13014 | Songwriter
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Andi is a mathematician, a computer scientist, and a songwriter. After spending so much time writing songs, he finally writes a catchy melody that he thought as his best creation. However, the singer who will sing the song/melody has a unique vocal range, thus, an adjustment may be needed.
A melody is defined as a sequence of $N$ notes which are represented by integers. Let $A$ be the original melody written by Andi. Andi needs to adjust $A$ into a new melody $B$ such that for every $i$ where $1 \le i < N$ :
- If $A_i < A_{i+1}$ , then $B_i < B_{i+1}$ .
- If $A_i = A_{i+1}$ , then $B_i = B_{i+1}$ .
- If $A_i > A_{i+1}$ , then $B_i > B_{i+1}$ .
- $|B_i - B_{i+1}| \le K$ , i.e. the difference between two successive notes is no larger than $K$ .
Moreover, the singer also requires that all notes are within her vocal range, i.e. $L \le B_i \le R$ for all $1 \le i \le N$ .Help Andi to determine whether such $B$ exists, and find the lexicographically smallest $B$ if it exists. A melody $X$ is lexicographically smaller than melody $Y$ if and only if there exists $j$ ( $1 \le j \le N$ ) such that $X_i = Y_i$ for all $i < j$ and $X_{j} < Y_{j}$ .
For example, consider a melody $A = \{1,3,5,6,7,8,9,10,3,7,8,9,10,11,12,12\}$ as shown in the following figure. The diagonal arrow up in the figure implies that $A_i < A_{i+1}$ , the straight right arrow implies that $A_i = A_{i+1}$ , and the diagonal arrow down implies that $A_i > A_{i+1}$ .
Supposed we want to make a new melody with $L = 1$ , $R = 8$ , and $K = 6$ . The new melody $B = \{1,2,3,4,5,6,7,8,2,3,4,5,6,7,8,8\}$ as shown in the figure satisfies all the requirements, and it is the lexicographically smallest possible.
A melody is defined as a sequence of $N$ notes which are represented by integers. Let $A$ be the original melody written by Andi. Andi needs to adjust $A$ into a new melody $B$ such that for every $i$ where $1 \le i < N$ :
- If $A_i < A_{i+1}$ , then $B_i < B_{i+1}$ .
- If $A_i = A_{i+1}$ , then $B_i = B_{i+1}$ .
- If $A_i > A_{i+1}$ , then $B_i > B_{i+1}$ .
- $|B_i - B_{i+1}| \le K$ , i.e. the difference between two successive notes is no larger than $K$ .
Moreover, the singer also requires that all notes are within her vocal range, i.e. $L \le B_i \le R$ for all $1 \le i \le N$ .Help Andi to determine whether such $B$ exists, and find the lexicographically smallest $B$ if it exists. A melody $X$ is lexicographically smaller than melody $Y$ if and only if there exists $j$ ( $1 \le j \le N$ ) such that $X_i = Y_i$ for all $i < j$ and $X_{j} < Y_{j}$ .
For example, consider a melody $A = \{1,3,5,6,7,8,9,10,3,7,8,9,10,11,12,12\}$ as shown in the following figure. The diagonal arrow up in the figure implies that $A_i < A_{i+1}$ , the straight right arrow implies that $A_i = A_{i+1}$ , and the diagonal arrow down implies that $A_i > A_{i+1}$ .
Supposed we want to make a new melody with $L = 1$ , $R = 8$ , and $K = 6$ . The new melody $B = \{1,2,3,4,5,6,7,8,2,3,4,5,6,7,8,8\}$ as shown in the figure satisfies all the requirements, and it is the lexicographically smallest possible.
输入格式
Input begins with a line containing four integers: $N$ $L$ $R$ $K$ ( $1 \le N \le 100\,000$ ; $1 \le L \le R \le 10^9$ ; $1 \le K \le 10^9$ ) representing the number of notes in the melody, the vocal range ( $L$ and $R$ ), and the maximum difference between two successive notes in the new melody, respectively. The next line contains $N$ integers: $A_i$ ( $1 \le A_i \le 10^9$ ) representing the original melody.
输出格式
Output in a line $N$ integers (each separated by a single space) representing the lexicographically smallest melody satisfying all the requirements, or output -1 if there is no melody satisfying all the requirements. Note that it might be possible that the lexicographically smallest melody which satisfies all the requirements to be the same as the original melody.
输入输出样例
输入 #1
16 1 8 6 1 3 5 6 7 8 9 10 3 7 8 9 10 11 12 12
输出 #1
1 2 3 4 5 6 7 8 2 3 4 5 6 7 8 8
输入 #2
16 1 8 6 1 3 5 6 7 8 9 10 3 7 8 9 10 11 12 13
输出 #2
-1
输入 #3
16 1 10 10 1 3 5 6 7 8 9 10 3 7 8 9 1 11 12 13
输出 #3
1 2 3 4 5 6 7 8 1 2 3 4 1 2 3 4
Explanation for the sample input/output #1
This is the example from the problem description.
This is the example from the problem description.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted