惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
SegmentFault 最新的问题
Google DeepMind News
Google DeepMind News
G
Google Developers Blog
Martin Fowler
Martin Fowler
MongoDB | Blog
MongoDB | Blog
月光博客
月光博客
Jina AI
Jina AI
宝玉的分享
宝玉的分享
人人都是产品经理
人人都是产品经理
D
DataBreaches.Net
V
V2EX
WordPress大学
WordPress大学
T
The Blog of Author Tim Ferriss
Last Week in AI
Last Week in AI
B
Blog
博客园 - 叶小钗
小众软件
小众软件
Stack Overflow Blog
Stack Overflow Blog
P
Proofpoint News Feed
A
About on SuperTechFans
J
Java Code Geeks
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Y
Y Combinator Blog
Microsoft Security Blog
Microsoft Security Blog

博客园 - 北叶青藤

2096. Step-By-Step Directions From a Binary Tree Node to Another Find path from root to a target node in Binary Tree When Dijkstra Algorithm Should be Use? 1188. Design Bounded Blocking Queue 1115. Print FooBar Alternately 1114. Print in Order 1242. Web Crawler Multithreaded Python Multi-threading bot ip Log Rate Limiter Same Word of HTML Labels Most Frequent Call Chain remove prefix in a words list 1102. Path With Maximum Minimum Value Property Booking Optimizer minimum number 755. Pour Water Keyword Tagging in Reviews with Overlapping Matches Retryer Function Implementation 1125. Smallest Sufficient Team Print the terrain Split stay 滑雪问题 845. Longest Mountain in Array 723. Candy Crush 1539. Kth Missing Positive Number 1650. Lowest Common Ancestor of a Binary Tree III 424. Longest Repeating Character Replacement 843. Guess the Word 551. Student Attendance Record I
Task scheduling problem
北叶青藤 · 2026-02-22 · via 博客园 - 北叶青藤

Maximize task profits by their ddl.  input: [(taskName, ddl, profit)], output: ([taskOrder], maxProfit)

每个task只需要花一天时间,一天只可以做一个task

 1 def maximize_task_profits(tasks):
 2     if not tasks:
 3         return [], 0
 4 
 5     tasks.sort(key=lambda x: x[2], reverse=True)
 6     max_deadline = max(task[1] for task in tasks)
 7     # 时间槽,从 1 开始
 8     slots = [None] * (max_deadline + 1)
 9 
10     total_profit = 0
11 
12     for name, ddl, profit in tasks:
13         for day in range(ddl, 0, -1):
14             if slots[day] is None:
15                 slots[day] = name
16                 total_profit += profit
17                 break
18 
19     task_order = [task for task in slots[1:] if task is not None]
20 
21     return task_order, total_profit