Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit da4639b

Browse files
committed
Solve 1626. Best Team With No Conflicts
1 parent b5f04b8 commit da4639b

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

‎16/1626-Best_Team_With_No_Conflicts.kt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
class Solution {
2+
3+
data class Player(val age: Int, val score: Int)
4+
5+
fun bestTeamScore(scores: IntArray, ages: IntArray): Int {
6+
val n = scores.size
7+
val teamScores = IntArray(n) { 0 }
8+
val playerList = ages.mapIndexed { i, age -> Player(age, scores[i])}
9+
.sortedWith(compareBy({ it.age }, { it.score }))
10+
.toList()
11+
12+
for (i in 0 until n) {
13+
teamScores[i] = playerList[i].score
14+
15+
for (j in 0 until i) {
16+
if (playerList[j].score <= playerList[i].score) {
17+
teamScores[i] = maxOf(teamScores[i], teamScores[j] + playerList[i].score)
18+
}
19+
}
20+
}
21+
22+
return teamScores.max() ?: -1
23+
}
24+
25+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /