检查以下代码问题并修改,def max_assignments(A): A = sorted(A, key=lambda x: x[1]) current_day = 1 count = 0 for duration, deadline in A: if current_day + duration - 1 <= deadline: count += 1 current_day += duration return count A = [[2, 4], [3, 5], [1, 2], [4, 7], [1, 1]]
时间: 2023-04-09 08:03:23 浏览: 81
找质数代码matlab-Number_Theory_and_cryptography_assignments:Number_Theory_an
修改后的代码如下:
def max_assignments(A):
A = sorted(A, key=lambda x: x[1])
current_day = 1
count = 0
for duration, deadline in A:
if current_day + duration - 1 <= deadline:
count += 1
current_day += duration
return count
A = [[2, 4], [3, 5], [1, 2], [4, 7], [1, 1]]
print(max_assignments(A))
输出结果为3,表示最多可以完成3项任务。
阅读全文