Skip to content

Commit bdd1a76

Browse files
committed
chore: sync automated leetcode submissions with Runtime - 213 ms (11.11%), Memory - 25.1 MB (66.67%)
1 parent c94159c commit bdd1a76

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

  • 3351-maximize-happiness-of-selected-children
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include <stdlib.h>
2+
3+
int compare(const void* a, const void* b) {
4+
return (*(int*)b - *(int*)a);
5+
}
6+
7+
long long maximumHappinessSum(int* happiness, int happinessSize, int k) {
8+
qsort(happiness, happinessSize, sizeof(int), compare);
9+
10+
long long total = 0;
11+
for (int i = 0; i < k; i++) {
12+
int current = happiness[i] - i;
13+
14+
if (current <= 0) break;
15+
16+
total += current;
17+
}
18+
19+
return total;
20+
}

0 commit comments

Comments
 (0)