← 返回 amazon 的题目列表Max Subjects Number
类型:online_judge
Given an array that represents the scores of each subject, and an integer k as the maximum number of subjects allowed. Your task is to find the maximum sum of scores ensuring the number of selected subjects does not exceed k. You can assume that the input is valid and a subset meeting the condition always exists.
Input
An integer array scores representing the scores of each subject.
An integer k
Output Return the maximum sum of scores.
Example
Input: scores = [4, 5, 1, 3], k = 2
Output: 9
Explanation Select the top two subjects with the highest scores, which are 5 and 4, and the sum is 9.
Example
Input
4 5 1 3
2