def optimize_tasks(tasks):
    tasks.sort(key=lambda x: x[0] - x[1], reverse=True)
    return tasks

tasks = [(1, 2), (2, 5), (4, 1)]
print(optimize_tasks(tasks))

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: