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

推荐订阅源

爱范儿
爱范儿
量子位
人人都是产品经理
人人都是产品经理
小众软件
小众软件
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园 - Franky
Recent Announcements
Recent Announcements
A
About on SuperTechFans
Microsoft Security Blog
Microsoft Security Blog
N
Netflix TechBlog - Medium
H
Help Net Security
博客园 - 三生石上(FineUI控件)
博客园 - 司徒正美
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
MyScale Blog
MyScale Blog
The Cloudflare Blog
S
SegmentFault 最新的问题
H
Hackread – Cybersecurity News, Data Breaches, AI and More
J
Java Code Geeks
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
P
Proofpoint News Feed
宝玉的分享
宝玉的分享
Vercel News
Vercel News

博客园 - 北叶青藤

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