classSolution { funbestTeamScore(scores: IntArray, ages: IntArray): Int { val members = Array(scores.size) { i -> intArrayOf(ages[i], scores[i]) }.sortedWith(compareBy({ it[0] }, { it[1] })) //sortWith { a, b -> if (a[0] != b[0]) a[0] - b[0] else a[1] - b[1] }这么写的话力扣的编译器会过不了 val dp = IntArray(scores.size) { i -> members[i][1] }
for (i in members.indices) { for (j in0 until i) { if (members[i][1] >= members[j][1]) { dp[i] = Math.max(dp[i], dp[j] + members[i][1]) } } } return dp.max()!! } }