CF1252E.Songwriter

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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 NN notes which are represented by integers. Let AA be the original melody written by Andi. Andi needs to adjust AA into a new melody BB such that for every ii where 1i<N1 \le i < N :

  • If Ai<Ai+1A_i < A_{i+1} , then Bi<Bi+1B_i < B_{i+1} .
  • If Ai=Ai+1A_i = A_{i+1} , then Bi=Bi+1B_i = B_{i+1} .
  • If Ai>Ai+1A_i > A_{i+1} , then Bi>Bi+1B_i > B_{i+1} .
  • BiBi+1K|B_i - B_{i+1}| \le K , i.e. the difference between two successive notes is no larger than KK .

Moreover, the singer also requires that all notes are within her vocal range, i.e. LBiRL \le B_i \le R for all 1iN1 \le i \le N .Help Andi to determine whether such BB exists, and find the lexicographically smallest BB if it exists. A melody XX is lexicographically smaller than melody YY if and only if there exists jj ( 1jN1 \le j \le N ) such that Xi=YiX_i = Y_i for all i<ji < j and Xj<YjX_{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}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 Ai<Ai+1A_i < A_{i+1} , the straight right arrow implies that Ai=Ai+1A_i = A_{i+1} , and the diagonal arrow down implies that Ai>Ai+1A_i > A_{i+1} .

Supposed we want to make a new melody with L=1L = 1 , R=8R = 8 , and K=6K = 6 . The new melody B={1,2,3,4,5,6,7,8,2,3,4,5,6,7,8,8}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: NN LL RR KK ( 1N1000001 \le N \le 100\,000 ; 1LR1091 \le L \le R \le 10^9 ; 1K1091 \le K \le 10^9 ) representing the number of notes in the melody, the vocal range ( LL and RR ), and the maximum difference between two successive notes in the new melody, respectively. The next line contains NN integers: AiA_i ( 1Ai1091 \le A_i \le 10^9 ) representing the original melody.

输出格式

Output in a line NN 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.

首页