Created
September 16, 2024 13:32
-
-
Save h0tk3y/369aecda72fdbf1cdaafeb58c060b9b3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun main() { | |
val n = readln().toInt() | |
val input = readln().split(" ").map { it.toInt() } | |
val result = solve(input) | |
if (result == null) { | |
println("NO") | |
} else { | |
println("YES") | |
println(result.joinToString(" ")) | |
} | |
} | |
fun solve(input: List<Int>): List<Int>? { | |
var previous = 0 | |
val delta = mutableListOf<Int>() | |
input.forEach { item -> | |
val expectedAtLeast = previous + 1 | |
val actual = when (item) { | |
-1 -> expectedAtLeast | |
else -> { | |
if (item < expectedAtLeast) return@solve null | |
item | |
} | |
} | |
delta.add(actual - previous) | |
previous = actual | |
} | |
return delta | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment