class Solution {
public int bestTeamScore(int[] scores, int[] ages) {
int n=ages.length;
Player[] players= new Player[n];
for(int i=0;i<n;i++){
players[i]=new Player(ages[i],scores[i]);
}
Arrays.sort(players,(a,b)-> b.age==a.age? a.score-b.score : a.age-b.age);



int[] dp = new int[n];
dp[0]=players[0].score;
int max= dp[0];
for(int i = 1; i<n; i++) {
dp[i]=players[i].score;
for(int j =0; j<i; j++) {
if(players[j].score <= players[i].score) {
dp[i] = Math.max(dp[i],players[i].score + dp[j]);

}
}
max = Math.max(dp[i], max);
}

return max;

}
class Player{
int age;
int score;
public Player(int age, int score){
this.age=age;
this.score=score;
}
}
}

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Why Sleep Is the Most Underrated Tool for Good Health, Longevity, and Productivity

Grilled Guacamole variables

5 advantages of headless Content Management Systems

So you want to tackle the mainframe?

Retrieve and Analyze DeFi Data With Keyko’s Python Library

How to manage Elixir versions on Mac or Linux — getting started with Elixir

Exploring Selenium Interactions with the Kotlin REPL

Expanding vocabulary is perhaps important to learn new things, but I believe that sense about…

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Abhinay Gupta

Abhinay Gupta

More from Medium

LeetCode 206. Reverse a Linked List

Think 3 cup trick

Permutation Split (code chef Question)

Greedy Algorithm

FINDING A ROLE MODEL