Skip to content

Instantly share code, notes, and snippets.

@h0tk3y
Created September 16, 2024 13:32
Show Gist options
  • Save h0tk3y/369aecda72fdbf1cdaafeb58c060b9b3 to your computer and use it in GitHub Desktop.
Save h0tk3y/369aecda72fdbf1cdaafeb58c060b9b3 to your computer and use it in GitHub Desktop.
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