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 } val num = readLineInt() var numArrPorsonPoint = Array(100, {0}) val pointArr = readLineIntArray() val answerPerson = readLineIntArray() var maxPoint = 0 var gattablePoint = 0 for (i in 0..(num-1)) { if (answerPerson[i] == 0) { gattablePoint += pointArr[i] } else { numArrPorsonPoint[answerPerson[i]-1] += pointArr[i] if (numArrPorsonPoint[answerPerson[i]-1] > maxPoint) { maxPoint = numArrPorsonPoint[answerPerson[i]-1] } } } if (gattablePoint >= maxPoint) { println("YES") } else { println("NO") } }