QOJ.ac

QOJ

Type: Editorial

Status: Open

Posted by: Milmon

Posted at: 2026-03-31 16:26:16

Last updated: 2026-03-31 16:26:20

Back to Problem

题解

对于两个相邻的编号 $i, j$ 若 $a_i - k > a_j$ 那么必须将 $a_j$ 调整为 $a_i - k$。按照从前往后和从后往前各调整一轮即可符合条件,这是因为第二轮调整时只会使得后面的数增大,不会破坏第一轮调整得到的性质。

时间复杂度为 $\mathcal{O}(n)$。

Comments

No comments yet.