1626.cpp (596B)
1 class Solution { 2 public: 3 int bestTeamScore(vector<int> &scores, vector<int> &ages) { 4 int n = scores.size(), res = 0; 5 vector<pair<int, int>> v(n); 6 for (int i = 0; i < n; i++) 7 v[i] = {ages[i], scores[i]}; 8 sort(v.begin(), v.end()); 9 10 vector<int> dp(n, 0); 11 for (int i = 0; i < n; i++) { 12 int total = 0; 13 for (int j = 0; j < i; j++) { 14 if (v[j].second <= v[i].second) dp[i] = max(dp[i], dp[j]); 15 } 16 res = max(res, dp[i] += v[i].second); 17 } 18 19 return res; 20 } 21 };