def maxSatisfaction(satisfaction):
res = total = 0
satisfaction.sort()
print(satisfaction)
while satisfaction and satisfaction[-1]+total>0:
total += satisfaction.pop()
res += total
print(satisfaction,total,res)
return res
a = [-2,5,-1,0,3,-3]
maxSatisfaction(a)
# 5*6+3*5+0-3-2*2-3
C++
Java
Python
C
C
JavaScript
Ruby
Swift
Go
Scala
Kotlin
Rust
PHP