Untitled

mail@pastecode.io avatar
unknown
kotlin
a month ago
637 B
7
Indexable
Never
fun main() {
    val `in` = Scanner(System.`in`)
    val n = `in`.nextLong()
    val ar = LongArray(n.toInt())
    val pre = LongArray(n.toInt()) { 0 }
    val suff = LongArray(n.toInt()) { 0 }
    var ans: Long = Long.MIN_VALUE
    for (i in 0 until n.toInt()) {
        ar[i] = `in`.nextLong()
    }

    pre[0] = 0
    for (i in 1 until n.toInt()) {
        pre[i] = (pre[i - 1] + ar[i - 1]) / 2
    }

    suff[n.toInt() - 1] = 0
    for (i in n.toInt() - 2 downTo 0) {
        suff[i] = (suff[i + 1] + ar[i + 1]) / 2
    }

    for (i in 0 until n.toInt()) {
        ans = max(ans, ar[i] + pre[i] + suff[i])
    }
    println(ans)
}
Leave a Comment