mirror of
https://github.com/lWolvesl/leetcode.git
synced 2026-01-12 18:08:38 +08:00
routine
This commit is contained in:
18
25/12/3075.cpp
Normal file
18
25/12/3075.cpp
Normal file
@@ -0,0 +1,18 @@
|
||||
#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;
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user