Skip to content

Commit 63b0c71

Browse files
committed
daily
1 parent c8c5ad4 commit 63b0c71

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-0
lines changed

my-submissions/e495.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class Solution:
2+
def findPoisonedDuration(self, timeSeries: List[int], duration: int) -> int:
3+
return duration + sum(min(duration, y - x) for x, y in zip(timeSeries, timeSeries[1:]))

my-submissions/m1578.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class Solution:
2+
def minCost(self, colors: str, neededTime: List[int]) -> int:
3+
output = 0
4+
curr = 0
5+
6+
while curr < len(colors) :
7+
tot = neededTime[curr]
8+
color, maxx = colors[curr], neededTime[curr]
9+
10+
for i in range(curr + 1, len(colors)) :
11+
if colors[i] != color :
12+
break
13+
curr = i
14+
maxx = max(maxx, neededTime[i])
15+
tot += neededTime[i]
16+
17+
output += tot - maxx
18+
curr += 1
19+
20+
return output
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
class Solution:
2+
def getNumberOfBacklogOrders(self, orders: List[List[int]]) -> int:
3+
# min heap, max heap
4+
# (price, amount)
5+
sell_reqs, purchase_reqs = [], []
6+
for price, amount, order_type in orders :
7+
if order_type == 0 : # buy
8+
while sell_reqs and sell_reqs[0][0] <= price and amount > 0 :
9+
seller_price, seller_amout = sell_reqs[0]
10+
11+
if seller_amout <= amount :
12+
heappop(sell_reqs)
13+
else :
14+
sell_reqs[0][1] -= amount
15+
16+
amount = max(0, amount - seller_amout)
17+
18+
if amount > 0 :
19+
heappush(purchase_reqs, [-price, amount])
20+
continue
21+
22+
# sell
23+
while purchase_reqs and -purchase_reqs[0][0] >= price and amount > 0 :
24+
purchaser_price, purchaser_amount = purchase_reqs[0]
25+
purchaser_price *= -1
26+
27+
if purchaser_amount <= amount :
28+
heappop(purchase_reqs)
29+
else :
30+
purchase_reqs[0][1] -= amount
31+
32+
amount = max(0, amount - purchaser_amount)
33+
34+
if amount > 0 :
35+
heappush(sell_reqs, [price, amount])
36+
37+
return (sum(x[1] for x in sell_reqs) + sum(x[1] for x in purchase_reqs)) % (10 ** 9 + 7)

0 commit comments

Comments
 (0)