package Yukicoder /** * Created by hichikawa on 2015/11/12. */ fun main(args: Array) { fun readLineLongArray(): List { val str = readLine() as String val arrStr = str.split(" ") val ret = arrStr.map { it.toLong() } return ret } fun readLineLong(): Long { val str = readLine() as String return str.toLong() } fun readLineInt(): Int { val str = readLine() as String return str.toInt() } fun readLineIntArray() : List { val str = readLine() as String val arrStr = str.split(" ") val ret = arrStr.map { it.toInt() } return ret } fun readLineDoubleArray(): List { val str = readLine() as String val arrStr = str.split(" ") val ret = arrStr.map { it.toDouble() } return ret } fun decideMikata (mikataLevel : Array, mikataCount : Array) : Int{ var tmpIndex = 0 for (i in 1..(mikataLevel.size-1)) { if (mikataLevel[i] < mikataLevel[tmpIndex]) { tmpIndex = i } else if (mikataLevel[i] == mikataLevel[tmpIndex]) { if (mikataCount[i] < mikataCount[tmpIndex]) { tmpIndex = i } } } return tmpIndex } val num = readLineInt() var mikata = readLineIntArray().toTypedArray() val teki = readLineIntArray().toTypedArray() var ans = Int.MIN_VALUE for (i in 0..(num-1)) { // for (i in 0..2) { var mikataCount = Array(num , {0}) for (j in 0..(num-1)) { val attackIndex = decideMikata(mikata, mikataCount) mikata[attackIndex] += teki[(i+j)%num] / 2 mikataCount[attackIndex]++ } val tmpAns : Int = mikataCount.max() as Int if (ans < tmpAns) { ans = tmpAns } // for (inte in mikataCount) { // print(inte.toString() + " ") // } // println() // for (inte in mikata) { // print(inte.toString() + " ") // } // println() } println(ans) }