#P17192. [KOI 2026 #2] 拉开距离

    ID: 19508 远端评测题 1000ms 1024MiB 尝试: 0 已通过: 0 显示难度入门 上传者: 标签>Special Judge2026KOI(韩国)

[KOI 2026 #2] 拉开距离

Problem Description

There are NN students who will stand on a number line. On the number line, a larger value means a position further to the right.

The students stand from left to right in order of their indices from 11 to NN, and all positions must be integers.

Let the position of student ii (1≤i≤N1 \le i \le N) be BiB_i. The positions must satisfy the following conditions:

  • For each integer ii (1≤i≤N1 \le i \le N), student ii cannot stand to the right of position AiA_i. That is, Bi≤AiB_i \le A_i must hold.
  • Any two adjacent students must be at least KK apart. That is, for each integer ii (1≤i≤N−11 \le i \le N-1), Bi+1−Bi≥KB_{i+1} - B_i \ge K must hold.

When K=0K = 0, multiple students may stand at the same position.

The students want to make the position B1B_1 of student 11 as large as possible.

Find a standing plan [B1,B2,⋯ ,BN][B_1, B_2, \cdots, B_N] that satisfies all conditions and maximizes the value of B1B_1. If multiple plans exist, output any one of them.

It can be proven that at least one valid standing plan exists.

Input Format

The first line contains two integers NN and KK separated by spaces.

The second line contains NN integers A1,A2,⋯ ,ANA_1, A_2, \cdots, A_N separated by spaces.

Output Format

Output NN integers B1,B2,⋯ ,BNB_1, B_2, \cdots, B_N separated by spaces on the first line. The standing plan [B1,B2,⋯ ,BN][B_1, B_2, \cdots, B_N] must satisfy all conditions in the statement, and the value of B1B_1 must be maximized.

If multiple valid outputs exist, any one of them will be accepted.

5 2
1 4 10 9 13
1 4 6 9 12
4 0
5 2 7 3
2 2 3 3
4 3
2 1 5 9
-2 1 5 8

Hint

Constraints

  • All given numbers are integers.
  • 1≤N≤1001 \le N \le 100.
  • 0≤K≤100 \le K \le 10.
  • For each integer ii (1≤i≤N1 \le i \le N), 1≤Ai≤1001 \le A_i \le 100.

Subtasks

  1. (2525 points) For each integer ii (1≤i≤N−11 \le i \le N-1), Ai+1−Ai≥KA_{i+1} - A_i \ge K.
  2. (3535 points) K=0K = 0.
  3. (3030 points) Among all standing plans that satisfy the conditions, there exists a plan with 0≤B1≤1000 \le B_1 \le 100.
  4. (1010 points) No additional constraints.

Translated by ChatGPT-5.6.

Translated by ChatGPT 5