Advertisement
saurav_kalsoor

Help Meera - KOTLIN

Aug 12th, 2021
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 0.72 KB | None | 0 0
  1. package com.company
  2.  
  3. import java.util.*
  4.  
  5. fun main() {
  6.     val sc = Scanner(System.`in`)
  7.     val n = sc.nextInt()
  8.     val coins = Array(2) { IntArray(n) }
  9.     for (i in 0..1) {
  10.         for (j in 0 until n) coins[i][j] = sc.nextInt()
  11.     }
  12.     println(helpMeera(coins, n))
  13. }
  14.  
  15. fun helpMeera(coins: Array<IntArray>, n: Int): Int {
  16.     val top = IntArray(n)
  17.     val bottom = IntArray(n)
  18.     top[0] = coins[0][0]
  19.     bottom[n - 1] = coins[1][n - 1]
  20.     for (i in 1 until n)
  21.         top[i] = top[i - 1] + coins[0][i]
  22.     for (i in n - 2 downTo 0)
  23.         bottom[i] = bottom[i + 1] + coins[1][i]
  24.     var result = 0
  25.     for (i in 0 until n) {
  26.         result = Math.max(result, top[i] + bottom[i])
  27.     }
  28.     return result
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement