1
class Solution {
2
public int maxSatisfaction(int[] satisfaction) {
3
Arrays.sort(satisfaction);
4
if (satisfaction[satisfaction.length - 1] <= 0) {
5
return 0;
6
}
7

8
int res = 0;
9
int beforeSum = 0;
10
for (int i = satisfaction.length - 1; i >= 0; i--) {
11
int currNum = satisfaction[i];
12
beforeSum += currNum;
13
if (beforeSum >= 0) {
14
res += beforeSum;
15
} else {
16
return res;
17
}
18
}
19

20
return res;
21
}
22
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0