public int bestTeamScore(int[] scores, int[] ages) {
        int n = scores.length;
        int[][] union = new int[n][2];
        for (int i = 0; i < n; i++) {
            union[i][0] = scores[i];
            union[i][1] = ages[i];
        }

        Arrays.sort(union,(a,b)->{
            return a[0] == b[0] ? a[1] - b[1] : a[0] - b[0];});
        int[] dp = new int[n];
        int ans = 0;
        for (int i = 0; i < n; i++) {
            dp[i] = union[i][0];
            for (int j = 0; j < i; j++) {
                if (union[i][1] >= union[j][1]) {
                    dp[i] = Math.max(dp[j], dp[j] + union[i][0]);
                }
            }
            ans = Math.max(dp[i],ans);
        }
        return ans;
    }