Same as LIS, Here instead of maximum length of increasing subsequence, we need to find the maximum sum of increasing subsequence.

We will first sort the array on the basis of ages. Now the score array is same as the nums array given in LIS, the only change is here mums[i]≥ nuts[j];

Here’s the code: