Skip to content

Commit 781fcea

Browse files
committed
Time: 103 ms (0%), Space: 35.9 MB (0%) - LeetHub
1 parent 611deb8 commit 781fcea

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# time complexity: O(nlogn)
2+
# space complexity: O(n)
3+
from typing import List
4+
5+
6+
class Solution:
7+
def maxPoints(self, technique1: List[int], technique2: List[int], k: int) -> int:
8+
n = len(technique1)
9+
base = sum(technique2)
10+
gains = [technique1[i] - technique2[i] for i in range(n)]
11+
12+
gains.sort(reverse=True)
13+
total = base + sum(gains[:k])
14+
for g in gains[k:]:
15+
if g > 0:
16+
total += g
17+
return total
18+
19+
20+
technique1 = [5, 2, 10]
21+
technique2 = [10, 3, 8]
22+
k = 2
23+
print(Solution().maxPoints(technique1, technique2, k))
24+
technique1 = [10, 20, 30]
25+
technique2 = [5, 15, 25]
26+
k = 2
27+
print(Solution().maxPoints(technique1, technique2, k))
28+
technique1 = [1, 2, 3]
29+
technique2 = [4, 5, 6]
30+
k = 0
31+
print(Solution().maxPoints(technique1, technique2, k))

0 commit comments

Comments
 (0)