-
Notifications
You must be signed in to change notification settings - Fork 0
/
ReducingDishes.py
38 lines (30 loc) · 1.03 KB
/
ReducingDishes.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
class Solution:
def quickSort(self, arr, begin, end):
if begin >= end:
return
left = begin
right = end
pivot = arr[left]
while left < right:
while left < right and arr[right] >= pivot:
right -= 1
arr[left] = arr[right]
while left < right and arr[left] < pivot:
left += 1
arr[right] = arr[left]
arr[left] = pivot
self.quickSort(arr, begin, left-1)
self.quickSort(arr, left+1, end)
return
def maxSatisfaction(self, satisfaction: List[int]) -> int:
n = len(satisfaction)
self.quickSort(satisfaction, 0, n-1)
max = 0
for i in range(n):
likeTime = 0
for j in range(0, n-i):
likeTime += satisfaction[j] * (j+1)
del satisfaction[0]
if likeTime > max:
max = likeTime
return max