mirror of
https://github.com/lWolvesl/leetcode.git
synced 2026-01-12 18:08:38 +08:00
18 lines
429 B
C++
18 lines
429 B
C++
#include <algorithm>
|
|
#include <vector>
|
|
|
|
class Solution {
|
|
public:
|
|
long long maximumHappinessSum(std::vector<int> &happiness, int k) {
|
|
long long ans = 0;
|
|
std::sort(happiness.begin(), happiness.end(),
|
|
[](int a, int b) { return a > b; });
|
|
for (int i = 0; i < k && i < happiness.size(); i++) {
|
|
if (happiness[i] < i) {
|
|
break;
|
|
}
|
|
ans += happiness[i] - i;
|
|
}
|
|
return ans;
|
|
}
|
|
}; |