Skip to content

Commit c94159c

Browse files
committed
chore: sync automated leetcode submissions with Runtime - 540 ms (66.67%), Memory - 73.1 MB (66.67%)
1 parent be7467c commit c94159c

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

  • 3351-maximize-happiness-of-selected-children
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System;
2+
3+
public class Solution {
4+
public long MaximumHappinessSum(int[] happiness, int k) {
5+
Array.Sort(happiness);
6+
7+
long total = 0;
8+
int n = happiness.Length;
9+
10+
for (int i = 0; i < k; i++) {
11+
int currentVal = happiness[n - 1 - i] - i;
12+
if (currentVal <= 0) break;
13+
14+
total += (long)currentVal;
15+
}
16+
17+
return total;
18+
}
19+
}

0 commit comments

Comments
 (0)